Author: trygvis Date: Fri May 13 04:51:41 2005 New Revision: 170010 URL: http://svn.apache.org/viewcvs?rev=170010&view=rev Log: o Adding a first part of CruiceControl project builder. Added: maven/continuum/trunk/continuum-cc/ (with props) maven/continuum/trunk/continuum-cc/pom.xml maven/continuum/trunk/continuum-cc/src/ maven/continuum/trunk/continuum-cc/src/main/ maven/continuum/trunk/continuum-cc/src/main/java/ maven/continuum/trunk/continuum-cc/src/main/java/org/ maven/continuum/trunk/continuum-cc/src/main/java/org/apache/ maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/ maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/ maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/project/ maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/project/builder/ maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/project/builder/cc/ maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilder.java maven/continuum/trunk/continuum-cc/src/main/models/ maven/continuum/trunk/continuum-cc/src/main/models/cc-config.mdo.xml maven/continuum/trunk/continuum-cc/src/main/resources/ maven/continuum/trunk/continuum-cc/src/main/resources/META-INF/ maven/continuum/trunk/continuum-cc/src/main/resources/META-INF/plexus/ maven/continuum/trunk/continuum-cc/src/main/resources/META-INF/plexus/components.xml maven/continuum/trunk/continuum-cc/src/test/ maven/continuum/trunk/continuum-cc/src/test/java/ maven/continuum/trunk/continuum-cc/src/test/java/org/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/model/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/model/cc/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/model/cc/CruiseControlTest.java maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/project/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/project/builder/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/project/builder/cc/ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilderTest.java maven/continuum/trunk/continuum-cc/src/test/resources/ maven/continuum/trunk/continuum-cc/src/test/resources/config.xml Modified: maven/continuum/trunk/build.sh Modified: maven/continuum/trunk/build.sh URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/build.sh?rev=170010&r1=170009&r2=170010&view=diff ============================================================================== --- maven/continuum/trunk/build.sh (original) +++ maven/continuum/trunk/build.sh Fri May 13 04:51:41 2005 @@ -5,6 +5,7 @@ includes=\ continuum-api/pom.xml,\ +continuum-cc/pom.xml,\ continuum-core/pom.xml,\ continuum-model/pom.xml,\ continuum-web/pom.xml,\ Propchange: maven/continuum/trunk/continuum-cc/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Fri May 13 04:51:41 2005 @@ -0,0 +1,8 @@ +target +*~ +*.log +.classpath +.project +*.ipr +*.iws +*.iml Added: maven/continuum/trunk/continuum-cc/pom.xml URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-cc/pom.xml?rev=170010&view=auto ============================================================================== --- maven/continuum/trunk/continuum-cc/pom.xml (added) +++ maven/continuum/trunk/continuum-cc/pom.xml Fri May 13 04:51:41 2005 @@ -0,0 +1,17 @@ + + + continuum-parent + org.apache.maven.continuum + 1.0-alpha-2-SNAPSHOT + + 4.0.0 + continuum-cc + Continuum Model + + + org.apache.maven.continuum + continuum-core + 1.0-alpha-2-SNAPSHOT + + + Added: maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilder.java URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilder.java?rev=170010&view=auto ============================================================================== --- maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilder.java (added) +++ maven/continuum/trunk/continuum-cc/src/main/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilder.java Fri May 13 04:51:41 2005 @@ -0,0 +1,310 @@ +package org.apache.maven.continuum.project.builder.cc; + +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; + +import org.apache.maven.continuum.execution.ContinuumBuildExecutor; +import org.apache.maven.continuum.project.AntProject; +import org.apache.maven.continuum.project.ContinuumProject; +import org.apache.maven.continuum.project.MavenOneProject; +import org.apache.maven.continuum.project.builder.AbstractContinuumProjectBuilder; +import org.apache.maven.continuum.project.builder.ContinuumProjectBuilderException; +import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; + +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * @author Trygve Laugstøl + * @version $Id:$ + */ +public class CriuseControlProjectBuilder + extends AbstractContinuumProjectBuilder +{ + public static final String ID = "cc-builder"; + + private final static String[] IGNORED_MODIFICATION_SET_TYPES = new String[]{ + "alwaysbuild", + "buildstatus", + "forceonly", + }; + + private final static String[] IGNORED_SCHEDULE_TYPES = new String[]{ + "pause", + }; + + // ---------------------------------------------------------------------- + // ContinuumProjectBuilder Implementation + // ---------------------------------------------------------------------- + + public ContinuumProjectBuildingResult createProjectsFromMetadata( URL url ) + throws ContinuumProjectBuilderException + { + ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult(); + + Xpp3Dom dom = downloadAndBuildDom( url ); + + Xpp3Dom[] projects = dom.getChildren( "project" ); + + for ( int i = 0; i < projects.length; i++ ) + { + Xpp3Dom project = projects[ i ]; + + ContinuumProject continuumProject = findProject( project.getChild( "schedule" ) ); + + // ---------------------------------------------------------------------- + // Create the project + // ---------------------------------------------------------------------- + + String name = project.getAttribute( "name" ); + + if ( StringUtils.isEmpty( name ) ) + { + throw new ContinuumProjectBuilderException( "Missing required attribute 'name' from 'project' element." ); + } + + continuumProject.setName( name ); + + // ---------------------------------------------------------------------- + // Scm url + // ---------------------------------------------------------------------- + + Xpp3Dom modifactionsets = project.getChild( "modificationset" ); + + if ( modifactionsets == null ) + { + throw new ContinuumProjectBuilderException( "The configuration must contain at a 'modificationset' element." ); + } + + String scmUrl = findScmUrl( modifactionsets.getChildren() ); + + continuumProject.setScmUrl( scmUrl ); + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + Xpp3Dom publishers = project.getChild( "publishers" ); + + if ( publishers != null ) + { + String nagEmailAddress = findNagEmailAddress( publishers.getChild( "email" ) ); + + continuumProject.setNagEmailAddress( nagEmailAddress ); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + continuumProject.setVersion( "UNKNOWN" ); + + result.addProject( continuumProject ); + } + + return result; + } + + private ContinuumProject findProject( Xpp3Dom schedule ) + throws ContinuumProjectBuilderException + { + if ( schedule == null ) + { + throw new ContinuumProjectBuilderException( "The configuration has to include a 'schedule' element." ); + } + + ContinuumProject project = null; + + Xpp3Dom[] children = schedule.getChildren(); + + for ( int i = 0; i < children.length; i++ ) + { + Xpp3Dom child = children[ i ]; + + if ( contains( child.getName(), IGNORED_SCHEDULE_TYPES ) ) + { + continue; + } + + if ( child.getName().equals( "ant" ) ) + { + if ( project != null ) + { + throw new ContinuumProjectBuilderException( "A configuration can only have a single 'ant' or 'maven' schedule." ); + } + + project = new AntProject(); + + project.setExecutorId( ContinuumBuildExecutor.ANT_EXECUTOR_ID ); + } + else if ( child.getName().equals( "maven" ) ) + { + if ( project != null ) + { + throw new ContinuumProjectBuilderException( "A configuration can only have a single 'ant' or 'maven' schedule." ); + } + + project = new MavenOneProject(); + + project.setExecutorId( ContinuumBuildExecutor.MAVEN_ONE_EXECUTOR_ID ); + } + else + { + throw new ContinuumProjectBuilderException( "Can't handle schedule '" + schedule.getName() + "'. Continuum only supports 'ant' and 'maven' schedules." ); + } + } + + if ( project == null ) + { + throw new ContinuumProjectBuilderException( "There must be exactly one 'ant' or 'maven' build scheduled.." ); + } + + return project; + } + + private String findScmUrl( Xpp3Dom[] modifactionsets ) + throws ContinuumProjectBuilderException + { + String scmUrl = null; + + for ( int j = 0; j < modifactionsets.length; j++ ) + { + Xpp3Dom modifactionset = modifactionsets[ j ]; + + if ( contains( modifactionset.getName(), IGNORED_MODIFICATION_SET_TYPES ) ) + { + continue; + } + + if ( modifactionset.getName().equals( "cvs" ) ) + { + if ( scmUrl != null ) + { + throw new ContinuumProjectBuilderException( "A 'modificationset' element can only contain a single 'cvs' or 'svn' element." ); + } + + String cvsrot = modifactionset.getAttribute( "cvsroot" ); + + if ( StringUtils.isEmpty( cvsrot ) ) + { + throw new ContinuumProjectBuilderException( "A 'cvsroot' attribute is required when using a cvs modification set. The usage of 'localworkingcopy' is not supported." ); + } + + String tag = modifactionset.getAttribute( "tag" ); + + if ( StringUtils.isEmpty( tag ) ) + { + throw new ContinuumProjectBuilderException( "Continuum doesn't support CVS tags." ); + } + + scmUrl = "cvs:" + cvsrot; + } + else if ( modifactionset.getName().equals( "svn" ) ) + { + if ( scmUrl != null ) + { + throw new ContinuumProjectBuilderException( "A 'modificationset' element can only contain a single 'cvs' or 'svn' element." ); + } + + String repositoryLocation = modifactionset.getAttribute( "repositoryLocation" ); + + if ( StringUtils.isEmpty( repositoryLocation ) ) + { + throw new ContinuumProjectBuilderException( "A 'repositoryLocation' attribute is required when using a svn modification set. The usage of 'localworkingcopy' is not supported." ); + } + + scmUrl = "svn:" + repositoryLocation; + } + else + { + throw new ContinuumProjectBuilderException( "Unsupported modification set found '" + modifactionset.getName() + "'." ); + } + } + + if ( scmUrl == null ) + { + throw new ContinuumProjectBuilderException( "The configuration must contain at least one 'modificationset'." ); + } + + return scmUrl; + } + + private String findNagEmailAddress( Xpp3Dom email ) + { + if ( email == null ) + { + return null; + } + + Xpp3Dom[] failure = email.getChildren( "failure" ); + + if ( failure.length == 0 ) + { + return null; + } + + String nagEmailAddress = failure[ 0 ].getValue(); + + if ( StringUtils.isEmpty( nagEmailAddress ) ) + { + return null; + } + + return nagEmailAddress; + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + private boolean contains( String target, String[] data ) + { + for ( int i = 0; i < data.length; i++ ) + { + if ( data[ i ].equals( target ) ) + { + return true; + } + } + + return false; + } + + private Xpp3Dom downloadAndBuildDom( URL url ) + throws ContinuumProjectBuilderException + { + try + { + getLogger().info( "Downloading " + url ); + + return Xpp3DomBuilder.build( new InputStreamReader( url.openStream() ) ); + } + catch ( XmlPullParserException e ) + { + throw new ContinuumProjectBuilderException( "Error while parsing the CruiseControl configuration file.", e ); + } + catch ( IOException e ) + { + throw new ContinuumProjectBuilderException( "Error while downloading the CruiseControl configuration file.", e ); + } + } +} Added: maven/continuum/trunk/continuum-cc/src/main/models/cc-config.mdo.xml URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-cc/src/main/models/cc-config.mdo.xml?rev=170010&view=auto ============================================================================== --- maven/continuum/trunk/continuum-cc/src/main/models/cc-config.mdo.xml (added) +++ maven/continuum/trunk/continuum-cc/src/main/models/cc-config.mdo.xml Fri May 13 04:51:41 2005 @@ -0,0 +1,216 @@ + + cc-config + CruiseControlConfig + + + + package + org.apache.maven.continuum.model.cc + + + + + + CruiseControlConfig + 2.2.1 + + + system + 2.2.1 + + System + + + + plugins + 2.2.1 + + Plugin + * + + + + projects + 2.2.1 + + Project + * + + + + + + System + 2.2.1 + + + configuration + 2.2.1 + + Configuration + + + + + + Configuration + 2.2.1 + + + threads + 2.2.1 + + Threads + + + + + + Threads + 2.2.1 + + + count + 2.2.1 + int + + + + + Plugin + 2.2.1 + + + name + 2.2.1 + String + + + classname + 2.2.1 + String + + + + + Project + 2.2.1 + + + name + 2.2.1 + String + true + + + buildafterfailed + 2.2.1 + String + + + plugins + 2.2.1 + + Plugin + * + + + + dateformat + 2.2.1 + + DateFormat + + + + labelincrementer + 2.2.1 + + LabelIncrementer + + + + listeners + 2.2.1 + + CurrentBuildStatusListener + * + + + + bootstrappers + 2.2.1 + + Bootstrapper + * + + + + + + DateFormat + 2.2.1 + + + format + 2.2.1 + String + + + + + LabelIncrementer + 2.2.1 + + + defaultLabel + 2.2.1 + String + + + preBuildIncrementer + 2.2.1 + String + + + separator + 2.2.1 + String + + + + + CurrentBuildStatusListener + 2.2.1 + + + file + 2.2.1 + String + + + + + Bootstrapper + 2.2.1 + + + + AntBootstrapper + 2.2.1 + + + Added: maven/continuum/trunk/continuum-cc/src/main/resources/META-INF/plexus/components.xml URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-cc/src/main/resources/META-INF/plexus/components.xml?rev=170010&view=auto ============================================================================== --- maven/continuum/trunk/continuum-cc/src/main/resources/META-INF/plexus/components.xml (added) +++ maven/continuum/trunk/continuum-cc/src/main/resources/META-INF/plexus/components.xml Fri May 13 04:51:41 2005 @@ -0,0 +1,9 @@ + + + + org.apache.maven.continuum.project.builder.ContinuumProjectBuilder + cc-builder + org.apache.maven.continuum.project.builder.cc.CriuseControlProjectBuilder + + + Added: maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/model/cc/CruiseControlTest.java URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/model/cc/CruiseControlTest.java?rev=170010&view=auto ============================================================================== --- maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/model/cc/CruiseControlTest.java (added) +++ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/model/cc/CruiseControlTest.java Fri May 13 04:51:41 2005 @@ -0,0 +1,33 @@ +package org.apache.maven.continuum.model.cc; + +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import junit.framework.TestCase; + +/** + * @author Trygve Laugstøl + * @version $Id:$ + */ +public class CruiseControlTest + extends TestCase +{ + public void testBasic() + throws Exception + { + + } +} Added: maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilderTest.java URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilderTest.java?rev=170010&view=auto ============================================================================== --- maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilderTest.java (added) +++ maven/continuum/trunk/continuum-cc/src/test/java/org/apache/maven/continuum/project/builder/cc/CriuseControlProjectBuilderTest.java Fri May 13 04:51:41 2005 @@ -0,0 +1,43 @@ +package org.apache.maven.continuum.project.builder.cc; + +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.net.URL; + +import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder; +import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; + +import org.codehaus.plexus.PlexusTestCase; + +/** + * @author Trygve Laugstøl + * @version $Id:$ + */ +public class CriuseControlProjectBuilderTest + extends PlexusTestCase +{ + public void testBasic() + throws Exception + { + ContinuumProjectBuilder projectBuilder = (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE, + CriuseControlProjectBuilder.ID ); + + URL url = getTestFile( "src/test/resources/config.xml" ).toURL(); + + ContinuumProjectBuildingResult result = projectBuilder.createProjectsFromMetadata( url ); + } +} Added: maven/continuum/trunk/continuum-cc/src/test/resources/config.xml URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-cc/src/test/resources/config.xml?rev=170010&view=auto ============================================================================== --- maven/continuum/trunk/continuum-cc/src/test/resources/config.xml (added) +++ maven/continuum/trunk/continuum-cc/src/test/resources/config.xml Fri May 13 04:51:41 2005 @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + > + + + + + + +