You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2010/10/11 16:51:38 UTC
svn commit: r1021363 - in /directory/studio-plugin/trunk: ./
src/main/java/org/apache/directory/studio/maven/plugins/
Author: seelmann
Date: Mon Oct 11 14:51:37 2010
New Revision: 1021363
URL: http://svn.apache.org/viewvc?rev=1021363&view=rev
Log:
Pass inactive/deactivated profiles to forked maven
Modified:
directory/studio-plugin/trunk/pom.xml
directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java
directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java
Modified: directory/studio-plugin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/studio-plugin/trunk/pom.xml?rev=1021363&r1=1021362&r2=1021363&view=diff
==============================================================================
--- directory/studio-plugin/trunk/pom.xml (original)
+++ directory/studio-plugin/trunk/pom.xml Mon Oct 11 14:51:37 2010
@@ -8,9 +8,9 @@
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
@@ -39,9 +39,9 @@
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
-
+
<inceptionYear>2007</inceptionYear>
-
+
<issueManagement>
<system>JIRA</system>
<url>http://issues.apache.org/jira/browse/DIRSTUDIO</url>
@@ -64,7 +64,7 @@
<distMgmtSiteUrl>scpexe://people.apache.org/www/directory.apache.org/studio-plugin/gen-docs/${version}</distMgmtSiteUrl>
<skin.version>1.0.2-SNAPSHOT</skin.version>
</properties>
-
+
<build>
<plugins>
<plugin>
@@ -133,6 +133,11 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.2.1</version>
</dependency>
Modified: directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java
URL: http://svn.apache.org/viewvc/directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java?rev=1021363&r1=1021362&r2=1021363&view=diff
==============================================================================
--- directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java (original)
+++ directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/AbstractStudioMojo.java Mon Oct 11 14:51:37 2010
@@ -6,16 +6,16 @@
* 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.studio.maven.plugins;
@@ -37,10 +37,12 @@ import org.apache.maven.artifact.resolve
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Profile;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.release.exec.CommandLineFactory;
import org.apache.maven.shared.release.exec.DefaultCommandLineFactory;
@@ -58,7 +60,7 @@ import org.codehaus.plexus.util.cli.Comm
/**
* The abstract studio mojo
- *
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public abstract class AbstractStudioMojo extends AbstractMojo
@@ -66,7 +68,7 @@ public abstract class AbstractStudioMojo
/**
* To look up Archiver/UnArchiver implementations
- *
+ *
* @component role="org.codehaus.plexus.archiver.manager.ArchiverManager"
* @required
* @readonly
@@ -75,7 +77,7 @@ public abstract class AbstractStudioMojo
/**
* Location of the file.
- *
+ *
* @parameter expression="${project.build.directory}"
* @required
* @readonly
@@ -84,7 +86,7 @@ public abstract class AbstractStudioMojo
/**
* Used to look up Artifacts in the remote repository.
- *
+ *
* @component role="org.apache.maven.artifact.factory.ArtifactFactory"
* @required
* @readonly
@@ -93,7 +95,7 @@ public abstract class AbstractStudioMojo
/**
* Used to look up Artifacts in the remote repository.
- *
+ *
* @component role="org.apache.maven.artifact.resolver.ArtifactResolver"
* @required
* @readonly
@@ -102,7 +104,7 @@ public abstract class AbstractStudioMojo
/**
* Relativ Path to copy libraries to.
- *
+ *
* @parameter expression="${libraryPath}" default-value="lib"
* @required
* @readonly
@@ -111,7 +113,7 @@ public abstract class AbstractStudioMojo
/**
* Artifact collector, needed to resolve dependencies.
- *
+ *
* @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
* @required
* @readonly
@@ -128,7 +130,7 @@ public abstract class AbstractStudioMojo
/**
* Location of the local repository.
- *
+ *
* @parameter expression="${localRepository}"
* @readonly
* @required
@@ -137,7 +139,7 @@ public abstract class AbstractStudioMojo
/**
* List of Remote Repositories used by the resolver
- *
+ *
* @parameter expression="${project.remoteArtifactRepositories}"
* @readonly
* @required
@@ -146,17 +148,26 @@ public abstract class AbstractStudioMojo
/**
* POM
- *
+ *
* @parameter expression="${project}"
* @readonly
* @required
*/
protected MavenProject project;
+ /**
+ * The current build session instance. This is used for plugin manager API calls.
+ *
+ * @parameter expression="${session}"
+ * @required
+ * @readonly
+ */
+ private MavenSession session;
+
/**
* Unpack a file to a location
- *
+ *
* @param location
* The location to unpack the file to
* @param file
@@ -188,7 +199,7 @@ public abstract class AbstractStudioMojo
/**
* Pack a given location into a file
- *
+ *
* @param location
* A location to pack
* @param file
@@ -225,15 +236,17 @@ public abstract class AbstractStudioMojo
/**
- * Fork a maven goal
- *
- * @param goal
- * the goal
+ * Fork a maven goal.
+ *
+ * @param goal the goal
+ * @param activeProfileIds the active profile IDs
+ * @param inactiveProfileIds the inactive profile IDs
* @return the result
- * @throws MavenExecutorException
- * @throws CommandLineException
+ * @throws MavenExecutorException the maven executor exception
+ * @throws CommandLineException the command line exception
*/
- protected int forkMvnGoal( final String goal, List profiles ) throws MavenExecutorException, CommandLineException
+ protected int forkMvnGoal( final String goal, List<String> activeProfileIds, List<String> inactiveProfileIds )
+ throws MavenExecutorException, CommandLineException
{
CommandLineFactory commandLineFactory = new DefaultCommandLineFactory();
Commandline cl = commandLineFactory.createCommandLine( "mvn" );
@@ -246,19 +259,31 @@ public abstract class AbstractStudioMojo
cl.createArg().setValue( "--batch-mode" );
// Profiles ("-Pxxx") argument
- if ( ( profiles != null ) && ( profiles.size() > 0 ) )
+ if ( ( ( activeProfileIds != null ) && ( activeProfileIds.size() > 0 ) )
+ || ( ( inactiveProfileIds != null ) && ( inactiveProfileIds.size() > 0 ) ) )
{
StringBuilder sb = new StringBuilder();
sb.append( "-P" );
- for ( Object profileObject : profiles )
+
+ if ( ( activeProfileIds != null ) && ( activeProfileIds.size() > 0 ) )
{
- if ( profileObject instanceof Profile )
+ for ( String activeProfileId : activeProfileIds )
{
- Profile profile = ( Profile ) profileObject;
- sb.append( profile.getId() );
+ sb.append( activeProfileId );
sb.append( ',' );
}
}
+
+ if ( ( inactiveProfileIds != null ) && ( inactiveProfileIds.size() > 0 ) )
+ {
+ for ( String inactiveProfileId : inactiveProfileIds )
+ {
+ sb.append( '-' );
+ sb.append( inactiveProfileId );
+ sb.append( ',' );
+ }
+ }
+
sb.deleteCharAt( sb.length() - 1 );
cl.createArg().setValue( sb.toString() );
@@ -267,7 +292,63 @@ public abstract class AbstractStudioMojo
TeeOutputStream stdOut = new TeeOutputStream( System.out );
TeeOutputStream stdErr = new TeeOutputStream( System.err );
return ForkedMavenExecutor.executeCommandLine( cl, System.in, stdOut, stdErr );
+ }
+
+
+ /**
+ * Gets the active profile IDs.
+ *
+ * @return the active profile IDs
+ */
+ protected List<String> getActiveProfileIds()
+ {
+ List<String> activeProfileIds = new ArrayList<String>();
+
+ List activeProfiles = project.getActiveProfiles();
+ if ( activeProfiles != null )
+ {
+ for ( Object profileObject : activeProfiles )
+ {
+ if ( profileObject instanceof Profile )
+ {
+ Profile profile = ( Profile ) profileObject;
+ activeProfileIds.add( profile.getId() );
+ }
+ }
+ }
+
+ return activeProfileIds;
+ }
+
+
+ /**
+ * Gets the inactive profile IDs.
+ *
+ * @return the inactive profile IDs
+ */
+ protected List<String> getInactiveProfileIds()
+ {
+ List<String> inactiveProfileIds = new ArrayList<String>();
+ List<String> activeProfileIds = getActiveProfileIds();
+
+ DefaultProfileManager pm = new DefaultProfileManager( session.getContainer(), session.getExecutionProperties() );
+ MavenProject parent = project;
+ while ( parent != null )
+ {
+ for ( Profile profile : parent.getModel().getProfiles() )
+ {
+ String profileId = profile.getId();
+ pm.explicitlyActivate( profileId );
+ if ( !activeProfileIds.contains( profileId ) )
+ {
+ inactiveProfileIds.add( profileId );
+ }
+ }
+
+ parent = parent.getParent();
+ }
+ return inactiveProfileIds;
}
@@ -275,12 +356,12 @@ public abstract class AbstractStudioMojo
* Resolves the Artifact from the remote repository if necessary. If no
* version is specified, it will be retrieved from the dependency list or
* from the DependencyManagement section of the pom.
- *
+ *
* @param artifactItem
* containing information about artifact from plugin
* configuration.
* @return Artifact object representing the specified file.
- *
+ *
* @throws MojoExecutionException
* with a message if the version can't be found in
* DependencyManagement.
@@ -331,11 +412,11 @@ public abstract class AbstractStudioMojo
/**
* Tries to find missing version from dependancy list and dependency
* management. If found, the artifact is updated with the correct version.
- *
+ *
* It will first look for an exact match on
* artifactId/groupId/classifier/type and if it doesn't find a match, it
* will try again looking for artifactId and groupId only.
- *
+ *
* @param artifact
* representing configured file.
* @throws MojoExecutionException
@@ -358,7 +439,7 @@ public abstract class AbstractStudioMojo
/**
* Tries to find missing version from a list of dependencies. If found, the
* artifact is updated with the correct version.
- *
+ *
* @param artifact
* representing configured file.
* @param list
@@ -392,7 +473,7 @@ public abstract class AbstractStudioMojo
/**
* Complete the artifacts in the artifactItems list (e.g. complete with
* version number)
- *
+ *
* @throws MojoExecutionException
*/
protected void completeArtifactItems( List<ArtifactItem> artifactItems, boolean relaxed )
@@ -442,7 +523,7 @@ public abstract class AbstractStudioMojo
/**
* Delete a directory
- *
+ *
* @param path
* @return True if directory is deleted
*/
@@ -468,7 +549,7 @@ public abstract class AbstractStudioMojo
/**
* Return a list of artifacts nonscoped "provided"
- *
+ *
* @return The artifact list
*/
protected List<Artifact> createArtifactList()
Modified: directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java
URL: http://svn.apache.org/viewvc/directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java?rev=1021363&r1=1021362&r2=1021363&view=diff
==============================================================================
--- directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java (original)
+++ directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioCleanMojo.java Mon Oct 11 14:51:37 2010
@@ -6,16 +6,16 @@
* 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.studio.maven.plugins;
@@ -27,12 +27,12 @@ import org.apache.maven.plugin.MojoExecu
/**
* Clean stuff generated by studio:eclipse
- *
+ *
* @goal clean
* @execute phase="generate-resources"
* @requiresProject
* @since 1.0
- *
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class StudioCleanMojo extends AbstractStudioMojo
@@ -50,7 +50,7 @@ public class StudioCleanMojo extends Abs
{
try
{
- forkMvnGoal( "eclipse:clean", project.getActiveProfiles() );
+ forkMvnGoal( "eclipse:clean", getActiveProfileIds(), getInactiveProfileIds() );
}
catch ( Exception e )
{
Modified: directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java
URL: http://svn.apache.org/viewvc/directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java?rev=1021363&r1=1021362&r2=1021363&view=diff
==============================================================================
--- directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java (original)
+++ directory/studio-plugin/trunk/src/main/java/org/apache/directory/studio/maven/plugins/StudioEclipseMojo.java Mon Oct 11 14:51:37 2010
@@ -6,16 +6,16 @@
* 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.studio.maven.plugins;
@@ -50,13 +50,13 @@ import org.codehaus.plexus.util.xml.pull
* <li>Adapt ${basedir}/.classpath for artifacts nonscoped "provided"</li>
* </ul>
* </p>
- *
+ *
* @goal eclipse
* @execute phase="generate-resources"
* @requiresProject
* @requiresDependencyResolution runtime
* @since 1.0
- *
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class StudioEclipseMojo extends AbstractStudioMojo
@@ -79,7 +79,7 @@ public class StudioEclipseMojo extends A
/**
* Flag if artifacts shall be copied and eclipse specific files shall be adapted.
- *
+ *
* @parameter expression="${skip}" default-value="true"
* @required
* @since 1.0
@@ -88,7 +88,7 @@ public class StudioEclipseMojo extends A
/**
* Flag if manifest file shall be created.
- *
+ *
* @parameter expression="${createManifest}" default-value="false"
* @since 1.0.1
*/
@@ -101,7 +101,7 @@ public class StudioEclipseMojo extends A
{
try
{
- forkMvnGoal( "eclipse:eclipse", project.getActiveProfiles() );
+ forkMvnGoal( "eclipse:eclipse", getActiveProfileIds(), getInactiveProfileIds() );
}
catch ( Exception e )
{
@@ -142,7 +142,7 @@ public class StudioEclipseMojo extends A
{
try
{
- forkMvnGoal( "bundle:manifest", project.getActiveProfiles() );
+ forkMvnGoal( "bundle:manifest", getActiveProfileIds(), getInactiveProfileIds() );
}
catch ( Exception e )
{
@@ -154,7 +154,7 @@ public class StudioEclipseMojo extends A
/**
* Copy artifacts to ${basedir}/lib
- *
+ *
* @param list
* @throws IOException
*/
@@ -183,7 +183,7 @@ public class StudioEclipseMojo extends A
/**
* Adapt the ${basedir}/.classpath
- *
+ *
* @param list
*/
private void updateDotClasspath( List<Artifact> list ) throws IOException, XmlPullParserException
@@ -237,7 +237,7 @@ public class StudioEclipseMojo extends A
/**
* Adapt the ${basedir}/.project
- *
+ *
* @param list
*/
private void updateDotProject() throws IOException, XmlPullParserException