Author: carlos Date: Fri May 18 12:48:11 2007 New Revision: 539578 URL: http://svn.apache.org/viewvc?view=rev&rev=539578 Log: Added a new eclipse:to-maven goal deprecating old make-artifacts for trying a different naming convention
Added: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java (with props) maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipseToMavenTest.java - copied, changed from r538751, maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java Added: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java?view=auto&rev=539578 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java (added) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java Fri May 18 12:48:11 2007 @@ -0,0 +1,683 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.maven.plugin.eclipse; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.zip.ZipEntry; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.deployer.ArtifactDeployer; +import org.apache.maven.artifact.deployer.ArtifactDeploymentException; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.installer.ArtifactInstallationException; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.License; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.artifact.ProjectArtifactMetadata; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.components.interactivity.InputHandler; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; + +/** + * Add eclipse artifacts from an eclipse installation to the local repo. This mojo automatically analize the eclipse + * directory, copy plugins jars to the local maven repo, and generates appropriate poms. + * + * @author Fabrizio Giustina + * @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a> + * @version $Id$ + * @goal to-maven + * @requiresProject false + */ +public class EclipseToMavenMojo + extends AbstractMojo + implements Contextualizable +{ + + /** + * A pattern the <code>deployTo</code> param should match. + */ + private static final Pattern DEPLOYTO_PATTERN = Pattern.compile( "(.+)::(.+)::(.+)" ); + + /** + * A pattern for a 4 digit osgi version number. + */ + private static final Pattern VERSION_PATTERN = Pattern.compile( "(([0-9]+\\.)+[0-9]+)" ); + + /** + * Plexus container, needed to manually lookup components for deploy of artifacts. + */ + private PlexusContainer container; + + /** + * Local maven repository. + * + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + private ArtifactRepository localRepository; + + /** + * ArtifactFactory component. + * @component + */ + private ArtifactFactory artifactFactory; + + /** + * ArtifactInstaller component. + * @component + */ + protected ArtifactInstaller installer; + + /** + * ArtifactDeployer component. + * @component + */ + private ArtifactDeployer deployer; + + /** + * Eclipse installation dir. If not set, a value for this parameter will be asked on the command line. + * + * @parameter expression="${eclipseDir}" + */ + private File eclipseDir; + + /** + * Input handler, needed for comand line handling. + * @component + */ + protected InputHandler inputHandler; + + /** + * Strip qualifier (fourth token) from the plugin version. Qualifiers are for eclipse plugin the equivalent of + * timestamped snapshot versions for Maven, but the date is maintained also for released version (e.g. a jar + * for the release <code>3.2</code> can be named <code>org.eclipse.core.filesystem_1.0.0.v20060603.jar</code>. + * It's usually handy to not to include this qualifier when generating maven artifacts for major releases, while + * it's needed when working with eclipse integration/nightly builds. + * + * @parameter expression="${stripQualifier}" default-value="true" + */ + private boolean stripQualifier; + + /** + * Default token to use as a qualifier. Tipically qualifiers for plugins in the same eclipse build are different. + * This parameter can be used to "align" qualifiers so that all the plugins coming from the same eclipse build can + * be easily identified. For example, setting this to "M3" will force the pluging versions to be "*.*.*.M3" + * + * @parameter expression="${forcedQualifier}" + */ + private String forcedQualifier; + + /** + * Specifies a remote repository to which generated artifacts should be deployed to. If this property is specified, + * artifacts are also deployed to the remote repo. + * The format for this parameter is <code>id::layout::url</code> + * + * @parameter expression="${deployTo}" + */ + private String deployTo; + + /** + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( eclipseDir == null ) + { + getLog().info( "Eclipse directory? " ); + + String eclipseDirString; + try + { + eclipseDirString = inputHandler.readLine(); + } + catch ( IOException e ) + { + throw new MojoFailureException( "Unable to read from standard input" ); + } + eclipseDir = new File( eclipseDirString ); + } + + if ( !eclipseDir.isDirectory() ) + { + throw new MojoFailureException( "Directory " + eclipseDir.getAbsolutePath() + " doesn't exists" ); + } + + File pluginDir = new File( eclipseDir, "plugins" ); + + if ( !pluginDir.isDirectory() ) + { + throw new MojoFailureException( "Plugin directory " + pluginDir.getAbsolutePath() + " doesn't exists" ); + } + + File[] files = pluginDir.listFiles(); + + ArtifactRepository remoteRepo = resolveRemoteRepo(); + + if ( remoteRepo != null ) + { + getLog().info( "Will deploy artifacts to remote repository " + deployTo ); + } + + for ( int j = 0; j < files.length; j++ ) + { + processSingleFile( files[j], remoteRepo ); + + } + + } + + /** + * Process a single plugin jar/dir found in the target dir. + * @param file plugin jar or dir + * @param remoteRepo remote repository (if set) + * @throws MojoExecutionException if anything bad happens while parsing files + */ + private void processSingleFile( File file, ArtifactRepository remoteRepo ) + throws MojoExecutionException + { + + getLog().info( "Processing file " + file.getAbsolutePath() ); + + Manifest manifest = null; + Properties pluginProperties = new Properties(); + boolean wasUnpacked = false; + + // package directories in a temp jar + if ( file.isDirectory() ) + { + try + { + File manifestFile = new File( file, "META-INF/MANIFEST.MF" ); + if ( !manifestFile.exists() ) + { + getLog().warn( + "Plugin in folder " + file.getAbsolutePath() + + " does not have a manifest; skipping.." ); + return; + } + + File tmpJar = File.createTempFile( "mvn-eclipse", null ); + tmpJar.deleteOnExit(); + + JarArchiver jarArchiver = new JarArchiver(); + + jarArchiver.setDestFile( tmpJar ); + jarArchiver.addDirectory( file ); + jarArchiver.setManifest( manifestFile ); + jarArchiver.createArchive(); + + file = tmpJar; + wasUnpacked = true; + } + catch ( ArchiverException e ) + { + throw new MojoExecutionException( "Unable to jar plugin in folder " + file.getAbsolutePath(), e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Unable to jar plugin in folder " + file.getAbsolutePath(), e ); + } + } + + if ( file.getName().endsWith( ".jar" ) || wasUnpacked ) + { + try + { + // don't verify, jars created from unzipped plugin could have a bad signature + JarFile jar = new JarFile( file, false ); + manifest = jar.getManifest(); + pluginProperties = loadPluginProperties( jar ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Unable to read manifest or plugin properties for " + + file.getAbsolutePath() ); + } + } + else + { + getLog().debug( "Ignoring file " + file.getAbsolutePath() ); + return; + } + + if ( manifest == null ) + { + getLog().warn( "Jar " + file.getAbsolutePath() + " does not have a manifest; skipping.." ); + return; + } + + Attributes manifestEntries = manifest.getMainAttributes(); + + String bundleName = manifestEntries.getValue( "Bundle-SymbolicName" ); + + int separator = bundleName.indexOf( ";" ); + if ( separator > 0 ) + { + bundleName = StringUtils.substring( bundleName, 0, separator ); + } + bundleName = StringUtils.trim( bundleName ); + + String version = manifestEntries.getValue( "Bundle-Version" ); + + if ( bundleName == null || version == null ) + { + getLog().error( "Unable to read bundle name/version from manifest, skipping..." ); + return; + } + + version = osgiVersionToMavenVersion( version, forcedQualifier, stripQualifier ); + + String name = manifestEntries.getValue( "Bundle-Name" ); + + // if Bundle-Name is %pluginName fetch the full name from plugin.properties + if ( name != null && name.startsWith( "%" ) ) + { + String nameFromProperties = pluginProperties.getProperty( name.substring( 1 ) ); + if ( nameFromProperties != null ) + { + name = nameFromProperties; + } + } + + String requireBundle = manifestEntries.getValue( "Require-Bundle" ); + Dependency[] deps = parseDependencies( requireBundle ); + + String groupId = createGroupId( bundleName ); + String artifactId = createArtifactId( bundleName ); + + Model model = new Model(); + model.setModelVersion( "4.0.0" ); + model.setGroupId( groupId ); + model.setArtifactId( artifactId ); + model.setName( name ); + model.setVersion( version ); + + /* set the pom property to install unpacked if it was unpacked */ + if ( wasUnpacked ) + { + Properties properties = new Properties(); + properties.setProperty( InstallPluginsMojo.PROP_UNPACK_PLUGIN, Boolean.TRUE.toString() ); + model.setProperties( properties ); + } + + if ( groupId.startsWith( "org.eclipse" ) ) + { + // why do we need a parent? + + // Parent parent = new Parent(); + // parent.setGroupId( "org.eclipse" ); + // parent.setArtifactId( "eclipse" ); + // parent.setVersion( "1" ); + // model.setParent( parent ); + + // infer license for know projects, everything at eclipse is licensed under EPL + // maybe too simplicistic, but better than nothing + License license = new License(); + license.setName( "Eclipse Public License - v 1.0" ); + license.setUrl( "http://www.eclipse.org/org/documents/epl-v10.html" ); + model.addLicense( license ); + } + + if ( deps.length > 0 ) + { + for ( int k = 0; k < deps.length; k++ ) + { + model.getDependencies().add( deps[k] ); + } + + } + + FileWriter fw = null; + ArtifactMetadata metadata = null; + File pomFile = null; + Artifact pomArtifact = artifactFactory.createArtifact( groupId, artifactId, version, null, "pom" ); + Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, "jar" ); + try + { + pomFile = File.createTempFile( "pom-", ".xml" ); + + fw = new FileWriter( pomFile ); + pomFile.deleteOnExit(); + new MavenXpp3Writer().write( fw, model ); + metadata = new ProjectArtifactMetadata( pomArtifact, pomFile ); + pomArtifact.addMetadata( metadata ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error writing temporary pom file: " + e.getMessage(), e ); + } + finally + { + IOUtil.close( fw ); + } + + try + { + if ( remoteRepo != null ) + { + deployer.deploy( pomFile, pomArtifact, remoteRepo, localRepository ); + deployer.deploy( file, artifact, remoteRepo, localRepository ); + } + else + { + installer.install( pomFile, pomArtifact, localRepository ); + installer.install( file, artifact, localRepository ); + } + } + catch ( ArtifactDeploymentException e ) + { + throw new MojoExecutionException( "Unable to deploy artifact to repository.", e ); + } + catch ( ArtifactInstallationException e ) + { + throw new MojoExecutionException( "Unable to install artifact to repository.", e ); + } + finally + { + pomFile.delete(); + } + + } + + /** + * The 4th (build) token MUST be separed with "-" and not with "." in maven. A version with 4 dots is not parsed, + * and the whole string is considered a qualifier. See tests in DefaultArtifactVersion for reference. + * @param version initial version + * @param forcedQualifier build number + * @param stripQualifier always remove 4th token in version + * @return converted version + */ + protected String osgiVersionToMavenVersion( String version, String forcedQualifier, boolean stripQualifier ) + { + if ( stripQualifier && StringUtils.countMatches( version, "." ) > 2 ) + { + version = StringUtils.substring( version, 0, version.lastIndexOf( "." ) ); + } + else if ( StringUtils.countMatches( version, "." ) > 2 ) + { + int lastDot = version.lastIndexOf( "." ); + if ( StringUtils.isNotEmpty( forcedQualifier ) ) + { + version = StringUtils.substring( version, 0, lastDot ) + "-" + forcedQualifier; + } + else + { + version = StringUtils.substring( version, 0, lastDot ) + "-" + + StringUtils.substring( version, lastDot + 1, version.length() ); + } + } + return version; + } + + /** + * Resolves the deploy<code>deployTo</code> parameter to an <code>ArtifactRepository</code> instance (if set). + * + * @throws MojoFailureException + * @throws MojoExecutionException + * @return ArtifactRepository instance of null if <code>deployTo</code> is not set. + */ + private ArtifactRepository resolveRemoteRepo() + throws MojoFailureException, MojoExecutionException + { + if ( deployTo != null ) + { + Matcher matcher = DEPLOYTO_PATTERN.matcher( deployTo ); + + if ( !matcher.matches() ) + { + throw new MojoFailureException( deployTo, "Invalid syntax for repository.", + "Invalid syntax for remote repository. Use \"id::layout::url\"." ); + } + else + { + String id = matcher.group( 1 ).trim(); + String layout = matcher.group( 2 ).trim(); + String url = matcher.group( 3 ).trim(); + + ArtifactRepositoryLayout repoLayout; + try + { + repoLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, layout ); + } + catch ( ComponentLookupException e ) + { + throw new MojoExecutionException( "Cannot find repository layout: " + layout, e ); + } + + return new DefaultArtifactRepository( id, url, repoLayout ); + } + } + return null; + } + + /** + * [EMAIL PROTECTED] + */ + public void contextualize( Context context ) + throws ContextException + { + this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } + + /** + * Get the group id as the tokens until last dot + * e.g. <code>org.eclipse.jdt</code> -> <code>org.eclipse</code> + * @param bundleName bundle name + * @return group id + */ + protected String createGroupId( String bundleName ) + { + int i = bundleName.lastIndexOf( "." ); + if ( i > 0 ) + { + return bundleName.substring( 0, i ); + } + else + return bundleName; + } + + /** + * Get the artifact id as the tokens after last dot + * e.g. <code>org.eclipse.jdt</code> -> <code>jdt</code> + * @param bundleName bundle name + * @return artifact id + */ + protected String createArtifactId( String bundleName ) + { + int i = bundleName.lastIndexOf( "." ); + if ( i > 0 ) + { + return bundleName.substring( i + 1 ); + } + else + return bundleName; + } + + /** + * Parses the "Require-Bundle" and convert it to a list of dependencies. + * @param requireBundle "Require-Bundle" entry + * @return an array of <code>Dependency</code> + */ + protected Dependency[] parseDependencies( String requireBundle ) + { + if ( requireBundle == null ) + { + return new Dependency[0]; + } + + List dependencies = new ArrayList(); + + // first split + String[] splitAtComma = StringUtils.split( requireBundle, "," ); + ArrayList bundles = new ArrayList(); + + // not so easy, comma can also be contained in quoted string... find them and concatenate them back + for ( int j = 0; j < splitAtComma.length; j++ ) + { + String string = splitAtComma[j]; + if ( StringUtils.countMatches( string, "\"" ) % 2 != 0 ) + { + j++; + bundles.add( string + "," + splitAtComma[j] ); + continue; + } + bundles.add( string ); + } + + // now iterates on bundles and extract dependencies + for ( Iterator iter = bundles.iterator(); iter.hasNext(); ) + { + String[] bundleTokens = StringUtils.split( (String) iter.next(), ";" ); + + String bundleName = bundleTokens[0]; + String version = null; + boolean optional = false; + for ( int k = 1; k < bundleTokens.length; k++ ) + { + String string = bundleTokens[k]; + if ( string.startsWith( "bundle-version=" ) ) + { + version = StringUtils.strip( StringUtils.substring( string, string.indexOf( "=" ) + 1 ), "\"" ); + } + else if ( string.equalsIgnoreCase( "resolution:=optional" ) ) + { + optional = true; + } + } + + if ( version == null ) + { + getLog().info( "Missing version for bundle " + bundleName + ", assuming any version > 0" ); + version = "[0,)"; + } + + version = fixBuildNumberSeparator( version ); + + Dependency dep = new Dependency(); + dep.setGroupId( createGroupId( bundleName ) ); + dep.setArtifactId( createArtifactId( bundleName ) ); + dep.setVersion( version ); + dep.setOptional( optional ); + + dependencies.add( dep ); + + } + + return (Dependency[]) dependencies.toArray( new Dependency[dependencies.size()] ); + + } + + /** + * Fix the separator for the 4th token in a versions. In maven this must be "-", in OSGI it's "." + * @param versionRange input range + * @return modified version range + */ + protected String fixBuildNumberSeparator( String versionRange ) + { + // should not be called with a null versionRange, but a check doesn't hurt... + if ( versionRange == null ) + { + return null; + } + + StringBuffer newVersionRange = new StringBuffer(); + + Matcher matcher = VERSION_PATTERN.matcher( versionRange ); + + while ( matcher.find() ) + { + String group = matcher.group(); + + if ( StringUtils.countMatches( group, "." ) > 2 ) + { + // build number found, fix it + int lastDot = group.lastIndexOf( "." ); + group = StringUtils.substring( group, 0, lastDot ) + "-" + + StringUtils.substring( group, lastDot + 1, group.length() ); + } + matcher.appendReplacement( newVersionRange, group ); + } + + matcher.appendTail( newVersionRange ); + + return newVersionRange.toString(); + } + + /** + * Loads the plugin.properties file from a jar, usually needed in order to resolve the artifact name. + * @param file jar file + * @return loaded Properties (or an empty properties if no plugin.properties is found) + * @throws IOException for exceptions while reading the jar file + */ + private Properties loadPluginProperties( JarFile file ) + throws IOException + { + InputStream pluginPropertiesStream = null; + try + { + Properties pluginProperties = new Properties(); + ZipEntry jarEntry = file.getEntry( "plugin.properties" ); + if ( jarEntry != null ) + { + pluginPropertiesStream = file.getInputStream( jarEntry ); + pluginProperties.load( pluginPropertiesStream ); + } + return pluginProperties; + } + finally + { + if ( pluginPropertiesStream != null ) + { + pluginPropertiesStream.close(); + } + } + } + +} Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java?view=diff&rev=539578&r1=539577&r2=539578 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/MakeArtifactsMojo.java Fri May 18 12:48:11 2007 @@ -18,505 +18,41 @@ */ package org.apache.maven.plugin.eclipse; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; import java.util.StringTokenizer; -import java.util.jar.Attributes; -import java.util.jar.JarFile; -import java.util.jar.Manifest; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.zip.ZipEntry; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.deployer.ArtifactDeployer; -import org.apache.maven.artifact.deployer.ArtifactDeploymentException; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.installer.ArtifactInstallationException; -import org.apache.maven.artifact.installer.ArtifactInstaller; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.License; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Writer; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.project.artifact.ProjectArtifactMetadata; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.jar.JarArchiver; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.components.interactivity.InputHandler; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; -import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; /** * Add eclipse artifacts from an eclipse installation to the local repo. This mojo automatically analize the eclipse - * directory, copy plugins jars to the local maven repo, and generates appropriate poms (with packaging set to - * <code>eclipse-plugin</code>). + * directory, copy plugins jars to the local maven repo, and generates appropriate poms. + * + * Use <code>eclipse:to-maven</code> for the latest naming conventions in place, + * <code>groupId</code>.<code>artifactId</code>. * * @author Fabrizio Giustina + * @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a> * @version $Id$ * @goal make-artifacts * @requiresProject false + * @deprecated use [EMAIL PROTECTED] EclipseToMavenMojo} for the latest naming conventions */ public class MakeArtifactsMojo - extends AbstractMojo + extends EclipseToMavenMojo implements Contextualizable { /** - * A pattern the <code>deployTo</code> param should match. - */ - private static final Pattern DEPLOYTO_PATTERN = Pattern.compile( "(.+)::(.+)::(.+)" ); - - /** - * A pattern for a 4 digit osgi version number. - */ - private static final Pattern VERSION_PATTERN = Pattern.compile( "(([0-9]+\\.)+[0-9]+)" ); - - /** - * Plexus container, needed to manually lookup components for deploy of artifacts. - */ - private PlexusContainer container; - - /** - * Local maven repository. - * - * @parameter expression="${localRepository}" - * @required - * @readonly - */ - private ArtifactRepository localRepository; - - /** - * ArtifactFactory component. - * @component - */ - private ArtifactFactory artifactFactory; - - /** - * ArtifactInstaller component. - * @component - */ - protected ArtifactInstaller installer; - - /** - * ArtifactDeployer component. - * @component - */ - private ArtifactDeployer deployer; - - /** - * Eclipse installation dir. If not set, a value for this parameter will be asked on the command line. - * - * @parameter expression="${eclipseDir}" - */ - private File eclipseDir; - - /** - * Input handler, needed for comand line handling. - * @component - */ - protected InputHandler inputHandler; - - /** - * Strip qualifier (fourth token) from the plugin version. Qualifiers are for eclipse plugin the equivalent of - * timestamped snapshot versions for Maven, but the date is maintained also for released version (e.g. a jar - * for the release <code>3.2</code> can be named <code>org.eclipse.core.filesystem_1.0.0.v20060603.jar</code>. - * It's usually handy to not to include this qualifier when generating maven artifacts for major releases, while - * it's needed when working with eclipse integration/nightly builds. - * - * @parameter expression="${stripQualifier}" default-value="true" - */ - private boolean stripQualifier; - - /** - * Default token to use as a qualifier. Tipically qualifiers for plugins in the same eclipse build are different. - * This parameter can be used to "align" qualifiers so that all the plugins coming from the same eclipse build can - * be easily identified. For example, setting this to "M3" will force the pluging versions to be "*.*.*.M3" - * - * @parameter expression="${forcedQualifier}" - */ - private String forcedQualifier; - - /** - * Specifies a remote repository to which generated artifacts should be deployed to. If this property is specified, - * artifacts are also deployed to the remote repo. - * The format for this parameter is <code>id::layout::url</code> - * - * @parameter expression="${deployTo}" - */ - private String deployTo; - - /** - * @see org.apache.maven.plugin.Mojo#execute() - */ - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( eclipseDir == null ) - { - getLog().info( "Eclipse directory? " ); - - String eclipseDirString; - try - { - eclipseDirString = inputHandler.readLine(); - } - catch ( IOException e ) - { - throw new MojoFailureException( "Unable to read from standard input" ); - } - eclipseDir = new File( eclipseDirString ); - } - - if ( !eclipseDir.isDirectory() ) - { - throw new MojoFailureException( "Directory " + eclipseDir.getAbsolutePath() + " doesn't exists" ); - } - - File pluginDir = new File( eclipseDir, "plugins" ); - - if ( !pluginDir.isDirectory() ) - { - throw new MojoFailureException( "Plugin directory " + pluginDir.getAbsolutePath() + " doesn't exists" ); - } - - File[] files = pluginDir.listFiles(); - - ArtifactRepository remoteRepo = resolveRemoteRepo(); - - if ( remoteRepo != null ) - { - getLog().info( "Will deploy artifacts to remote repository " + deployTo ); - } - - for ( int j = 0; j < files.length; j++ ) - { - processSingleFile( files[j], remoteRepo ); - - } - - } - - /** - * Process a single plugin jar/dir found in the target dir. - * @param file plugin jar or dir - * @param remoteRepo remote repository (if set) - * @throws MojoExecutionException if anything bad happens while parsing files - */ - private void processSingleFile( File file, ArtifactRepository remoteRepo ) - throws MojoExecutionException - { - - getLog().info( "Processing file " + file.getAbsolutePath() ); - - Manifest manifest = null; - Properties pluginProperties = new Properties(); - boolean wasUnpacked = false; - - // package directories in a temp jar - if ( file.isDirectory() ) - { - try - { - File manifestFile = new File( file, "META-INF/MANIFEST.MF" ); - if ( !manifestFile.exists() ) - { - getLog().warn( - "Plugin in folder " + file.getAbsolutePath() - + " does not have a manifest; skipping.." ); - return; - } - - File tmpJar = File.createTempFile( "mvn-eclipse", null ); - tmpJar.deleteOnExit(); - - JarArchiver jarArchiver = new JarArchiver(); - - jarArchiver.setDestFile( tmpJar ); - jarArchiver.addDirectory( file ); - jarArchiver.setManifest( manifestFile ); - jarArchiver.createArchive(); - - file = tmpJar; - wasUnpacked = true; - } - catch ( ArchiverException e ) - { - throw new MojoExecutionException( "Unable to jar plugin in folder " + file.getAbsolutePath(), e ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Unable to jar plugin in folder " + file.getAbsolutePath(), e ); - } - } - - if ( file.getName().endsWith( ".jar" ) || wasUnpacked ) - { - try - { - // don't verify, jars created from unzipped plugin could have a bad signature - JarFile jar = new JarFile( file, false ); - manifest = jar.getManifest(); - pluginProperties = loadPluginProperties( jar ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Unable to read manifest or plugin properties for " - + file.getAbsolutePath() ); - } - } - else - { - getLog().debug( "Ignoring file " + file.getAbsolutePath() ); - return; - } - - if ( manifest == null ) - { - getLog().warn( "Jar " + file.getAbsolutePath() + " does not have a manifest; skipping.." ); - return; - } - - Attributes manifestEntries = manifest.getMainAttributes(); - - String artifactId = manifestEntries.getValue( "Bundle-SymbolicName" ); - - int separator = artifactId.indexOf( ";" ); - if ( separator > 0 ) - { - artifactId = StringUtils.substring( artifactId, 0, separator ); - } - artifactId = StringUtils.trim( artifactId ); - - String version = manifestEntries.getValue( "Bundle-Version" ); - - if ( artifactId == null || version == null ) - { - getLog().error( "Unable to read artifact/version from manifest, skipping..." ); - return; - } - - version = osgiVersionToMavenVersion( version, forcedQualifier, stripQualifier ); - - String name = manifestEntries.getValue( "Bundle-Name" ); - - // if Bundle-Name is %pluginName fetch the full name from plugin.properties - if ( name != null && name.startsWith( "%" ) ) - { - String nameFromProperties = pluginProperties.getProperty( name.substring( 1 ) ); - if ( nameFromProperties != null ) - { - name = nameFromProperties; - } - } - - String requireBundle = manifestEntries.getValue( "Require-Bundle" ); - Dependency[] deps = parseDependencies( requireBundle ); - - String groupId = null; - groupId = createGroupId( artifactId ); - - Model model = new Model(); - model.setModelVersion( "4.0.0" ); - model.setGroupId( groupId ); - model.setArtifactId( artifactId ); - model.setName( name ); - model.setVersion( version ); - - /* set the pom property to install unpacked if it was unpacked */ - if ( wasUnpacked ) - { - Properties properties = new Properties(); - properties.setProperty( InstallPluginsMojo.PROP_UNPACK_PLUGIN, Boolean.TRUE.toString() ); - model.setProperties( properties ); - } - - if ( groupId.startsWith( "org.eclipse" ) ) - { - // why do we need a parent? - - // Parent parent = new Parent(); - // parent.setGroupId( "org.eclipse" ); - // parent.setArtifactId( "eclipse" ); - // parent.setVersion( "1" ); - // model.setParent( parent ); - - // infer license for know projects, everything at eclipse is licensed under EPL - // maybe too simplicistic, but better than nothing - License license = new License(); - license.setName( "Eclipse Public License - v 1.0" ); - license.setUrl( "http://www.eclipse.org/org/documents/epl-v10.html" ); - model.addLicense( license ); - } - - if ( deps.length > 0 ) - { - for ( int k = 0; k < deps.length; k++ ) - { - model.getDependencies().add( deps[k] ); - } - - } - - FileWriter fw = null; - ArtifactMetadata metadata = null; - File pomFile = null; - Artifact pomArtifact = artifactFactory.createArtifact( groupId, artifactId, version, null, "pom" ); - Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, "jar" ); - try - { - pomFile = File.createTempFile( "pom-", ".xml" ); - - fw = new FileWriter( pomFile ); - pomFile.deleteOnExit(); - new MavenXpp3Writer().write( fw, model ); - metadata = new ProjectArtifactMetadata( pomArtifact, pomFile ); - pomArtifact.addMetadata( metadata ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error writing temporary pom file: " + e.getMessage(), e ); - } - finally - { - IOUtil.close( fw ); - } - - try - { - if ( remoteRepo != null ) - { - deployer.deploy( pomFile, pomArtifact, remoteRepo, localRepository ); - deployer.deploy( file, artifact, remoteRepo, localRepository ); - } - else - { - installer.install( pomFile, pomArtifact, localRepository ); - installer.install( file, artifact, localRepository ); - } - } - catch ( ArtifactDeploymentException e ) - { - throw new MojoExecutionException( "Unable to deploy artifact to repository.", e ); - } - catch ( ArtifactInstallationException e ) - { - throw new MojoExecutionException( "Unable to install artifact to repository.", e ); - } - finally - { - pomFile.delete(); - } - - } - - /** - * The 4th (build) token MUST be separed with "-" and not with "." in maven. A version with 4 dots is not parsed, - * and the whole string is considered a qualifier. See tests in DefaultArtifactVersion for reference. - * @param version initial version - * @param forcedQualifier build number - * @param stripQualifier always remove 4th token in version - * @return converted version - */ - protected String osgiVersionToMavenVersion( String version, String forcedQualifier, boolean stripQualifier ) - { - if ( stripQualifier && StringUtils.countMatches( version, "." ) > 2 ) - { - version = StringUtils.substring( version, 0, version.lastIndexOf( "." ) ); - } - else if ( StringUtils.countMatches( version, "." ) > 2 ) - { - int lastDot = version.lastIndexOf( "." ); - if ( StringUtils.isNotEmpty( forcedQualifier ) ) - { - version = StringUtils.substring( version, 0, lastDot ) + "-" + forcedQualifier; - } - else - { - version = StringUtils.substring( version, 0, lastDot ) + "-" - + StringUtils.substring( version, lastDot + 1, version.length() ); - } - } - return version; - } - - /** - * Resolves the deploy<code>deployTo</code> parameter to an <code>ArtifactRepository</code> instance (if set). - * - * @throws MojoFailureException - * @throws MojoExecutionException - * @return ArtifactRepository instance of null if <code>deployTo</code> is not set. - */ - private ArtifactRepository resolveRemoteRepo() - throws MojoFailureException, MojoExecutionException - { - if ( deployTo != null ) - { - Matcher matcher = DEPLOYTO_PATTERN.matcher( deployTo ); - - if ( !matcher.matches() ) - { - throw new MojoFailureException( deployTo, "Invalid syntax for repository.", - "Invalid syntax for remote repository. Use \"id::layout::url\"." ); - } - else - { - String id = matcher.group( 1 ).trim(); - String layout = matcher.group( 2 ).trim(); - String url = matcher.group( 3 ).trim(); - - ArtifactRepositoryLayout repoLayout; - try - { - repoLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, layout ); - } - catch ( ComponentLookupException e ) - { - throw new MojoExecutionException( "Cannot find repository layout: " + layout, e ); - } - - return new DefaultArtifactRepository( id, url, repoLayout ); - } - } - return null; - } - - /** - * [EMAIL PROTECTED] - */ - public void contextualize( Context context ) - throws ContextException - { - this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); - } - - /** - * Get the group id as the three first tokens in artifacts Id (e.g. <code>org.eclipse.jdt</code>) - * @param artifactId artifact id + * Get the group id as the three first tokens in artifacts Id + * e.g. <code>org.eclipse.jdt</code> -> <code>org.eclipse.jdt</code> + * @param bundleName bundle name * @return group id */ - String createGroupId( String artifactId ) + protected String createGroupId( String bundleName ) { - if ( StringUtils.countMatches( artifactId, "." ) > 1 ) + if ( StringUtils.countMatches( bundleName, "." ) > 1 ) { - StringTokenizer st = new StringTokenizer( artifactId, "." ); + StringTokenizer st = new StringTokenizer( bundleName, "." ); int i = 0; String groupId = ""; while ( st.hasMoreTokens() && ( i < 3 ) ) @@ -526,147 +62,17 @@ } return groupId.substring( 1 ); } - return artifactId; - } - - /** - * Parses the "Require-Bundle" and convert it to a list of dependencies. - * @param requireBundle "Require-Bundle" entry - * @return an array of <code>Dependency</code> - */ - protected Dependency[] parseDependencies( String requireBundle ) - { - if ( requireBundle == null ) - { - return new Dependency[0]; - } - - List dependencies = new ArrayList(); - - // first split - String[] splitAtComma = StringUtils.split( requireBundle, "," ); - ArrayList bundles = new ArrayList(); - - // not so easy, comma can also be contained in quoted string... find them and concatenate them back - for ( int j = 0; j < splitAtComma.length; j++ ) - { - String string = splitAtComma[j]; - if ( StringUtils.countMatches( string, "\"" ) % 2 != 0 ) - { - j++; - bundles.add( string + "," + splitAtComma[j] ); - continue; - } - bundles.add( string ); - } - - // now iterates on bundles and extract dependencies - for ( Iterator iter = bundles.iterator(); iter.hasNext(); ) - { - String[] bundleTokens = StringUtils.split( (String) iter.next(), ";" ); - - String artifactId = bundleTokens[0]; - String version = null; - boolean optional = false; - for ( int k = 1; k < bundleTokens.length; k++ ) - { - String string = bundleTokens[k]; - if ( string.startsWith( "bundle-version=" ) ) - { - version = StringUtils.strip( StringUtils.substring( string, string.indexOf( "=" ) + 1 ), "\"" ); - } - else if ( string.equalsIgnoreCase( "resolution:=optional" ) ) - { - optional = true; - } - } - - if ( version == null ) - { - getLog().info( "Missing version for artifact " + artifactId + ", assuming any version > 0" ); - version = "[0,)"; - } - - version = fixBuildNumberSeparator( version ); - - Dependency dep = new Dependency(); - dep.setArtifactId( artifactId ); - dep.setGroupId( createGroupId( artifactId ) ); - dep.setVersion( version ); - dep.setOptional( optional ); - - dependencies.add( dep ); - - } - - return (Dependency[]) dependencies.toArray( new Dependency[dependencies.size()] ); - - } - - /** - * Fix the separator for the 4th token in a versions. In maven this must be "-", in OSGI it's "." - * @param versionRange input range - * @return modified version range - */ - protected String fixBuildNumberSeparator( String versionRange ) - { - // should not be called with a null versionRange, but a check doesn't hurt... - if ( versionRange == null ) - { - return null; - } - - StringBuffer newVersionRange = new StringBuffer(); - - Matcher matcher = VERSION_PATTERN.matcher( versionRange ); - - while ( matcher.find() ) - { - String group = matcher.group(); - - if ( StringUtils.countMatches( group, "." ) > 2 ) - { - // build number found, fix it - int lastDot = group.lastIndexOf( "." ); - group = StringUtils.substring( group, 0, lastDot ) + "-" - + StringUtils.substring( group, lastDot + 1, group.length() ); - } - matcher.appendReplacement( newVersionRange, group ); - } - - matcher.appendTail( newVersionRange ); - - return newVersionRange.toString(); + return bundleName; } /** - * Loads the plugin.properties file from a jar, usually needed in order to resolve the artifact name. - * @param file jar file - * @return loaded Properties (or an empty properties if no plugin.properties is found) - * @throws IOException for exceptions while reading the jar file + * Get the artifact id equal to the bundleName + * e.g. <code>org.eclipse.jdt</code> -> <code>org.eclipse.jdt</code> + * @param bundleName bundle name + * @return artifact id */ - private Properties loadPluginProperties( JarFile file ) - throws IOException + protected String createArtifactId( String bundleName ) { - InputStream pluginPropertiesStream = null; - try - { - Properties pluginProperties = new Properties(); - ZipEntry jarEntry = file.getEntry( "plugin.properties" ); - if ( jarEntry != null ) - { - pluginPropertiesStream = file.getInputStream( jarEntry ); - pluginProperties.load( pluginPropertiesStream ); - } - return pluginProperties; - } - finally - { - if ( pluginPropertiesStream != null ) - { - pluginPropertiesStream.close(); - } - } + return bundleName; } - } Copied: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipseToMavenTest.java (from r538751, maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java) URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipseToMavenTest.java?view=diff&rev=539578&p1=maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java&r1=538751&p2=maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipseToMavenTest.java&r2=539578 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipseToMavenTest.java Fri May 18 12:48:11 2007 @@ -24,16 +24,17 @@ /** * @author Fabrizio Giustina + * @author <a href="mailto:[EMAIL PROTECTED]">Carlos Sanchez</a> * @version $Id$ */ -public class MakeArtifactsTest +public class EclipseToMavenTest extends TestCase { /** * Mojo under test. */ - private MakeArtifactsMojo mojo; + protected EclipseToMavenMojo mojo; /** * @see junit.framework.TestCase#setUp() @@ -42,7 +43,7 @@ throws Exception { super.setUp(); - mojo = new MakeArtifactsMojo(); + mojo = new EclipseToMavenMojo(); } /** @@ -55,13 +56,17 @@ + "bundle-version=\"[3.2.0,4.0.0)\",org.eclipse.core.expressions;bundle-version=\"[3.2.0,4.0.0)\"" ); assertEquals( 4, deps.length ); - assertEquals( "org.eclipse.ui", deps[0].getArtifactId() ); + assertEquals( "org.eclipse", deps[0].getGroupId() ); + assertEquals( "ui", deps[0].getArtifactId() ); assertEquals( "[3.2.0,4.0.0)", deps[0].getVersion() ); - assertEquals( "org.eclipse.ui.console", deps[1].getArtifactId() ); + assertEquals( "org.eclipse.ui", deps[1].getGroupId() ); + assertEquals( "console", deps[1].getArtifactId() ); assertEquals( "[3.1.100,4.0.0)", deps[1].getVersion() ); - assertEquals( "org.eclipse.help", deps[2].getArtifactId() ); + assertEquals( "org.eclipse", deps[2].getGroupId() ); + assertEquals( "help", deps[2].getArtifactId() ); assertEquals( "[3.2.0,4.0.0)", deps[2].getVersion() ); - assertEquals( "org.eclipse.core.expressions", deps[3].getArtifactId() ); + assertEquals( "org.eclipse.core", deps[3].getGroupId() ); + assertEquals( "expressions", deps[3].getArtifactId() ); assertEquals( "[3.2.0,4.0.0)", deps[3].getVersion() ); } @@ -76,13 +81,17 @@ + "bundle-version=\"[3.2.0.1,4.0.0.2)\",org.eclipse.core.expressions;bundle-version=\"[3.2.0.0,4.0.0.0)\"" ); assertEquals( 4, deps.length ); - assertEquals( "org.eclipse.ui", deps[0].getArtifactId() ); + assertEquals( "org.eclipse", deps[0].getGroupId() ); + assertEquals( "ui", deps[0].getArtifactId() ); assertEquals( "[3.2.0-0,4.0.0-0)", deps[0].getVersion() ); - assertEquals( "org.eclipse.ui.console", deps[1].getArtifactId() ); + assertEquals( "org.eclipse.ui", deps[1].getGroupId() ); + assertEquals( "console", deps[1].getArtifactId() ); assertEquals( "[3.1.100-0,4.0.0-0)", deps[1].getVersion() ); - assertEquals( "org.eclipse.help", deps[2].getArtifactId() ); + assertEquals( "org.eclipse", deps[2].getGroupId() ); + assertEquals( "help", deps[2].getArtifactId() ); assertEquals( "[3.2.0-1,4.0.0-2)", deps[2].getVersion() ); - assertEquals( "org.eclipse.core.expressions", deps[3].getArtifactId() ); + assertEquals( "org.eclipse.core", deps[3].getGroupId() ); + assertEquals( "expressions", deps[3].getArtifactId() ); assertEquals( "[3.2.0-0,4.0.0-0)", deps[3].getVersion() ); } @@ -92,10 +101,22 @@ public void testCreateGroupId() { assertEquals( "test", mojo.createGroupId( "test" ) ); - assertEquals( "org.eclipse", mojo.createGroupId( "org.eclipse" ) ); - assertEquals( "org.eclipse.jdt", mojo.createGroupId( "org.eclipse.jdt" ) ); + assertEquals( "org", mojo.createGroupId( "org.eclipse" ) ); + assertEquals( "org.eclipse", mojo.createGroupId( "org.eclipse.jdt" ) ); assertEquals( "org.eclipse.jdt", mojo.createGroupId( "org.eclipse.jdt.apt" ) ); - assertEquals( "org.eclipse.jdt", mojo.createGroupId( "org.eclipse.jdt.apt.core" ) ); + assertEquals( "org.eclipse.jdt.apt", mojo.createGroupId( "org.eclipse.jdt.apt.core" ) ); + } + + /** + * Test the generation of a artifactId from a bundle symbolic name. + */ + public void testCreateArtifactId() + { + assertEquals( "test", mojo.createArtifactId( "test" ) ); + assertEquals( "eclipse", mojo.createArtifactId( "org.eclipse" ) ); + assertEquals( "jdt", mojo.createArtifactId( "org.eclipse.jdt" ) ); + assertEquals( "apt", mojo.createArtifactId( "org.eclipse.jdt.apt" ) ); + assertEquals( "core", mojo.createArtifactId( "org.eclipse.jdt.apt.core" ) ); } public void testOsgiVersionToMavenVersion() Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java?view=diff&rev=539578&r1=539577&r2=539578 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/MakeArtifactsTest.java Fri May 18 12:48:11 2007 @@ -18,24 +18,18 @@ */ package org.apache.maven.plugin.eclipse; -import junit.framework.TestCase; - import org.apache.maven.model.Dependency; /** * @author Fabrizio Giustina * @version $Id$ + * @deprecated use [EMAIL PROTECTED] EclipseToMavenTest} */ public class MakeArtifactsTest - extends TestCase + extends EclipseToMavenTest { /** - * Mojo under test. - */ - private MakeArtifactsMojo mojo; - - /** * @see junit.framework.TestCase#setUp() */ protected void setUp() @@ -98,16 +92,16 @@ assertEquals( "org.eclipse.jdt", mojo.createGroupId( "org.eclipse.jdt.apt.core" ) ); } - public void testOsgiVersionToMavenVersion() + /** + * Test the generation of a artifactId from a bundle symbolic name. + */ + public void testCreateArtifactId() { - assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3", null, false ) ); - assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3", "20060101", false ) ); - assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3", null, true ) ); - assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3", "20060101", true ) ); - - assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3.1", null, true ) ); - assertEquals( "1.2.3", mojo.osgiVersionToMavenVersion( "1.2.3.1", "20060101", true ) ); - assertEquals( "1.2.3-20060101", mojo.osgiVersionToMavenVersion( "1.2.3.1", "20060101", false ) ); - assertEquals( "1.2.3-1", mojo.osgiVersionToMavenVersion( "1.2.3.1", null, false ) ); + assertEquals( "test", mojo.createArtifactId( "test" ) ); + assertEquals( "org.eclipse", mojo.createArtifactId( "org.eclipse" ) ); + assertEquals( "org.eclipse.jdt", mojo.createArtifactId( "org.eclipse.jdt" ) ); + assertEquals( "org.eclipse.jdt.apt", mojo.createArtifactId( "org.eclipse.jdt.apt" ) ); + assertEquals( "org.eclipse.jdt.apt.core", mojo.createArtifactId( "org.eclipse.jdt.apt.core" ) ); } + }