You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2008/08/04 14:14:28 UTC
svn commit: r682353 -
/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
Author: vsiveton
Date: Mon Aug 4 05:14:28 2008
New Revision: 682353
URL: http://svn.apache.org/viewvc?rev=682353&view=rev
Log:
o reformat code
o improved code readingness
Modified:
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java?rev=682353&r1=682352&r2=682353&view=diff
==============================================================================
--- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java (original)
+++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java Mon Aug 4 05:14:28 2008
@@ -100,10 +100,7 @@
}
catch ( ProfileActivationException e )
{
- String error = "Error obtaining external Profiles.";
- if ( getLog().isErrorEnabled() )
- getLog().error( error, e );
- throw new MojoExecutionException( error, e );
+ throw new MojoExecutionException( "Error obtaining external Profiles:" + e.getMessage(), e );
}
// Attempt to obtain settings profiles
@@ -116,19 +113,24 @@
if ( null == pm.getExplicitlyActivatedIds() || pm.getExplicitlyActivatedIds().size() == 0 )
{
if ( getLog().isWarnEnabled() )
+ {
getLog().warn( "No profiles detected!" );
+ }
}
else
{
// This feels more like a hack to filter out inactive profiles, there is no 'direct'
// way to query activation status on a Profile instance.
Map allProfilesByIds = pm.getProfilesById();
+
// active Profiles will be a subset of *all* profiles
List activeProfiles = project.getActiveProfiles();
for ( Iterator itr = activeProfiles.iterator(); itr.hasNext(); )
{
Profile activeProfile = (Profile) itr.next();
- // we already have the active profiles for the project, so remove them from the list of all profiles.
+
+ // we already have the active profiles for the project, so remove them from the list of all
+ // profiles.
allProfilesByIds.remove( activeProfile.getId() );
}
@@ -140,6 +142,7 @@
descriptionBuffer.append( "\tProfile Id: " ).append( p.getId() );
descriptionBuffer.append( " (Active: true , Source: " ).append( p.getSource() ).append( ")\n" );
}
+
// display inactive profiles
Iterator it = allProfilesByIds.keySet().iterator();
while ( it.hasNext() )
@@ -147,7 +150,7 @@
Profile p = (Profile) allProfilesByIds.get( (String) it.next() );
descriptionBuffer.append( "\tProfile Id: " ).append( p.getId() );
- descriptionBuffer.append( " (Active: false , Source: " ).append( p.getSource() ).append( ")\n" );
+ descriptionBuffer.append( " (Active: false , Source: " ).append( p.getSource() ).append( ")\n" );
}
}
}
@@ -188,40 +191,46 @@
private void loadProjectExternalProfiles( ProfileManager profileManager, File projectDir )
throws ProfileActivationException
{
- if ( projectDir != null )
+ if ( projectDir == null )
{
- if ( getLog().isDebugEnabled() )
- getLog().debug( "Attempting to read profiles from external profiles.xml..." );
- try
+ return;
+ }
+
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Attempting to read profiles from external profiles.xml..." );
+ }
+
+ try
+ {
+ DefaultMavenProfilesBuilder profilesBuilder = new DefaultMavenProfilesBuilder();
+ ProfilesRoot root = profilesBuilder.buildProfiles( projectDir );
+ if ( root != null )
{
- ProfilesRoot root = null;
- DefaultMavenProfilesBuilder profilesBuilder = new DefaultMavenProfilesBuilder();
- root = profilesBuilder.buildProfiles( projectDir );
- if ( root != null )
+ for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )
{
- for ( Iterator it = root.getProfiles().iterator(); it.hasNext(); )
- {
- org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next();
- Profile converted = ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile );
- profileManager.addProfile( converted );
- profileManager.explicitlyActivate( converted.getId() );
- }
+ org.apache.maven.profiles.Profile rawProfile = (org.apache.maven.profiles.Profile) it.next();
+
+ Profile converted = ProfilesConversionUtils.convertFromProfileXmlProfile( rawProfile );
+ profileManager.addProfile( converted );
+ profileManager.explicitlyActivate( converted.getId() );
}
- else if ( getLog().isDebugEnabled() )
- getLog().debug( "ProfilesRoot was found to be NULL" );
- }
- catch ( IOException e )
- {
- throw new ProfileActivationException(
- "Cannot read profiles.xml resource from directory: " + projectDir,
- e );
}
- catch ( XmlPullParserException e )
+ else if ( getLog().isDebugEnabled() )
{
- throw new ProfileActivationException( "Cannot parse profiles.xml resource from directory: "
- + projectDir, e );
+ getLog().debug( "ProfilesRoot was found to be NULL" );
}
}
+ catch ( IOException e )
+ {
+ throw new ProfileActivationException( "Cannot read profiles.xml resource from directory: "
+ + projectDir, e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new ProfileActivationException( "Cannot parse profiles.xml resource from directory: "
+ + projectDir, e );
+ }
}
/**
@@ -232,24 +241,30 @@
*/
private void loadProjectPomProfiles( ProfileManager profilesManager, MavenProject project )
{
- if ( null != project )
+ if ( project == null )
{
+ // shouldn't happen as this mojo requires a project
if ( getLog().isDebugEnabled() )
- getLog().debug( "Attempting to read profiles from pom.xml..." );
- // Attempt to obtain the list of profiles from pom.xml
- Iterator it = project.getModel().getProfiles().iterator();
- while ( it.hasNext() )
- {
- Profile profile = (Profile) it.next();
- profilesManager.addProfile( profile );
- profilesManager.explicitlyActivate( profile.getId() );
+ {
+ getLog().debug( "No pom.xml found to read Profiles from." );
}
+
+ return;
}
- else
+
+ if ( getLog().isDebugEnabled() )
{
- // shouldn't happen as this mojo requires a project
- if ( getLog().isDebugEnabled() )
- getLog().debug( "No pom.xml found to read Profiles from." );
+ getLog().debug( "Attempting to read profiles from pom.xml..." );
+ }
+
+ // Attempt to obtain the list of profiles from pom.xml
+ Iterator it = project.getModel().getProfiles().iterator();
+ while ( it.hasNext() )
+ {
+ Profile profile = (Profile) it.next();
+
+ profilesManager.addProfile( profile );
+ profilesManager.explicitlyActivate( profile.getId() );
}
}
@@ -261,23 +276,29 @@
*/
private void loadSettingsProfiles( ProfileManager profileManager, Settings settings )
{
- if ( null != settings )
+ if ( settings == null )
{
if ( getLog().isDebugEnabled() )
- getLog().debug( "Attempting to read profiles from settings.xml..." );
- Iterator it = settings.getProfiles().iterator();
- while ( it.hasNext() )
- {
- Profile profile = SettingsUtils.convertFromSettingsProfile( (org.apache.maven.settings.Profile) it
- .next() );
- profileManager.addProfile( profile );
- profileManager.explicitlyActivate( profile.getId() );
+ {
+ getLog().debug( "No settings.xml detected." );
}
+
+ return;
}
- else
+
+ if ( getLog().isDebugEnabled() )
{
- if ( getLog().isDebugEnabled() )
- getLog().debug( "No settings.xml detected." );
+ getLog().debug( "Attempting to read profiles from settings.xml..." );
+ }
+
+ Iterator it = settings.getProfiles().iterator();
+ while ( it.hasNext() )
+ {
+ org.apache.maven.settings.Profile rawProfile = (org.apache.maven.settings.Profile) it.next();
+
+ Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
+ profileManager.addProfile( profile );
+ profileManager.explicitlyActivate( profile.getId() );
}
}
}