Author: vsiveton Date: Tue Jan 22 16:18:42 2008 New Revision: 614391 URL: http://svn.apache.org/viewvc?rev=614391&view=rev Log: MSITE-290: Move logic from AbstractSiteMojo and AbstractSiteRenderingMojo for Doxia related stuff
o used new shared maven-doxia-tools Modified: maven/plugins/trunk/maven-site-plugin/pom.xml maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java Modified: maven/plugins/trunk/maven-site-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/pom.xml?rev=614391&r1=614390&r2=614391&view=diff ============================================================================== --- maven/plugins/trunk/maven-site-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-site-plugin/pom.xml Tue Jan 22 16:18:42 2008 @@ -173,6 +173,11 @@ <artifactId>maven-settings</artifactId> <version>2.0</version> </dependency> + <dependency> + <groupId>org.apache.maven.reporting</groupId> + <artifactId>maven-reporting-api</artifactId> + <version>2.0.4</version> + </dependency> <!-- Doxia --> <dependency> @@ -219,9 +224,9 @@ </dependency> <dependency> - <groupId>org.apache.maven.reporting</groupId> - <artifactId>maven-reporting-api</artifactId> - <version>2.0.4</version> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-doxia-tools</artifactId> + <version>1.0-SNAPSHOT</version> </dependency> <!-- Wagon --> Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java?rev=614391&r1=614390&r2=614391&view=diff ============================================================================== --- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java (original) +++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java Tue Jan 22 16:18:42 2008 @@ -23,6 +23,7 @@ import org.apache.maven.doxia.site.decoration.DecorationModel; import org.apache.maven.doxia.site.decoration.Menu; import org.apache.maven.doxia.site.decoration.MenuItem; +import org.apache.maven.doxia.tools.SiteTool; import org.apache.maven.model.Model; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -77,6 +78,13 @@ * * @component */ + protected SiteTool siteTool; + + /** + * Internationalization. + * + * @component + */ protected I18N i18n; /** @@ -256,7 +264,7 @@ */ protected File getSiteDescriptorFile( File basedir, Locale locale ) { - String relativePath = getRelativePath( siteDirectory.getAbsolutePath(), basedir.getAbsolutePath() ); + String relativePath = siteTool.getRelativePath( siteDirectory.getAbsolutePath(), basedir.getAbsolutePath() ); File siteDescriptor = new File( relativePath, "site_" + locale.getLanguage() + ".xml" ); @@ -388,7 +396,7 @@ String baseUrl = project.getUrl(); if ( baseUrl != null ) { - selectedHref = getRelativePath( selectedHref, baseUrl ); + selectedHref = siteTool.getRelativePath( selectedHref, baseUrl ); } if ( selectedHref.endsWith( "/" ) ) @@ -512,204 +520,6 @@ return list == null || list.isEmpty(); } - protected String getRelativePath( String to, String from ) - { - URL toUrl = null; - URL fromUrl = null; - - String toPath = to; - String fromPath = from; - - try - { - toUrl = new URL( to ); - } - catch ( MalformedURLException e ) - { - try - { - toUrl = new File( to ).toURL(); - } - catch ( MalformedURLException e1 ) - { - getLog().warn( "Unable to load a URL for '" + to + "': " + e.getMessage() ); - } - } - - try - { - fromUrl = new URL( from ); - } - catch ( MalformedURLException e ) - { - try - { - fromUrl = new File( from ).toURL(); - } - catch ( MalformedURLException e1 ) - { - getLog().warn( "Unable to load a URL for '" + from + "': " + e.getMessage() ); - } - } - - if ( toUrl != null && fromUrl != null ) - { - // URLs, determine if they share protocol and domain info - - if ( ( toUrl.getProtocol().equalsIgnoreCase( fromUrl.getProtocol() ) ) - && ( toUrl.getHost().equalsIgnoreCase( fromUrl.getHost() ) ) - && ( toUrl.getPort() == fromUrl.getPort() ) ) - { - // shared URL domain details, use URI to determine relative path - - toPath = toUrl.getFile(); - fromPath = fromUrl.getFile(); - } - else - { - // dont share basic URL infomation, no relative available - - return to; - } - } - else if ( ( toUrl != null && fromUrl == null ) || ( toUrl == null && fromUrl != null ) ) - { - // one is a URL and the other isnt, no relative available. - - return to; - } - - // either the two locations are not URLs or if they are they - // share the common protocol and domain info and we are left - // with their URI information - - // normalise the path delimters - - toPath = new File( toPath ).getPath(); - fromPath = new File( fromPath ).getPath(); - - // strip any leading slashes if its a windows path - if ( toPath.matches( "^\\[a-zA-Z]:" ) ) - { - toPath = toPath.substring( 1 ); - } - if ( fromPath.matches( "^\\[a-zA-Z]:" ) ) - { - fromPath = fromPath.substring( 1 ); - } - - // lowercase windows drive letters. - - if ( toPath.startsWith( ":", 1 ) ) - { - toPath = toPath.substring( 0, 1 ).toLowerCase() + toPath.substring( 1 ); - } - if ( fromPath.startsWith( ":", 1 ) ) - { - fromPath = fromPath.substring( 0, 1 ).toLowerCase() + fromPath.substring( 1 ); - } - - // check for the presence of windows drives. No relative way of - // traversing from one to the other. - - if ( ( toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) ) - && ( !toPath.substring( 0, 1 ).equals( fromPath.substring( 0, 1 ) ) ) ) - { - // they both have drive path element but they dont match, no - // relative path - - return to; - } - - if ( ( toPath.startsWith( ":", 1 ) && !fromPath.startsWith( ":", 1 ) ) - || ( !toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) ) ) - { - - // one has a drive path element and the other doesnt, no relative - // path. - - return to; - - } - - // use tokeniser to traverse paths and for lazy checking - StringTokenizer toTokeniser = new StringTokenizer( toPath, File.separator ); - StringTokenizer fromTokeniser = new StringTokenizer( fromPath, File.separator ); - - int count = 0; - - // walk along the to path looking for divergence from the from path - while ( toTokeniser.hasMoreTokens() && fromTokeniser.hasMoreTokens() ) - { - if ( File.separatorChar == '\\' ) - { - if ( !fromTokeniser.nextToken().equalsIgnoreCase( toTokeniser.nextToken() ) ) - { - break; - } - } - else - { - if ( !fromTokeniser.nextToken().equals( toTokeniser.nextToken() ) ) - { - break; - } - } - - count++; - } - - // reinitialise the tokenisers to count positions to retrieve the - // gobbled token - - toTokeniser = new StringTokenizer( toPath, File.separator ); - fromTokeniser = new StringTokenizer( fromPath, File.separator ); - - while ( count-- > 0 ) - { - fromTokeniser.nextToken(); - toTokeniser.nextToken(); - } - - String relativePath = ""; - - // add back refs for the rest of from location. - while ( fromTokeniser.hasMoreTokens() ) - { - fromTokeniser.nextToken(); - - relativePath += ".."; - - if ( fromTokeniser.hasMoreTokens() ) - { - relativePath += File.separatorChar; - } - } - - if ( relativePath.length() != 0 && toTokeniser.hasMoreTokens() ) - { - relativePath += File.separatorChar; - } - - // add fwd fills for whatevers left of to. - while ( toTokeniser.hasMoreTokens() ) - { - relativePath += toTokeniser.nextToken(); - - if ( toTokeniser.hasMoreTokens() ) - { - relativePath += File.separatorChar; - } - } - - if ( !relativePath.equals( to ) ) - { - getLog().debug( "Mapped url: " + to + " to relative path: " + relativePath ); - } - - return relativePath; - } - protected void populateProjectParentMenu( DecorationModel decorationModel, Locale locale, MavenProject parentProject, boolean keepInheritedRefs ) { @@ -732,7 +542,7 @@ parentUrl += "/index.html"; } - parentUrl = getRelativePath( parentUrl, project.getUrl() ); + parentUrl = siteTool.getRelativePath( parentUrl, project.getUrl() ); if ( menu.getName() == null ) { Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java?rev=614391&r1=614390&r2=614391&view=diff ============================================================================== --- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java (original) +++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java Tue Jan 22 16:18:42 2008 @@ -36,6 +36,7 @@ import org.apache.maven.doxia.siterenderer.Renderer; import org.apache.maven.doxia.siterenderer.RendererException; import org.apache.maven.doxia.siterenderer.SiteRenderingContext; +import org.apache.maven.doxia.tools.SiteToolException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; @@ -193,13 +194,13 @@ } catch ( ArtifactResolutionException e ) { - throw new MojoExecutionException( - "The site descriptor cannot be resolved from the repository: " + e.getMessage(), e ); + throw new MojoExecutionException( "The site descriptor cannot be resolved from the repository: " + + e.getMessage(), e ); } catch ( IOException e ) { - throw new MojoExecutionException( - "The site descriptor cannot be resolved from the repository: " + e.getMessage(), e ); + throw new MojoExecutionException( "The site descriptor cannot be resolved from the repository: " + + e.getMessage(), e ); } } else @@ -231,9 +232,8 @@ } catch ( IOException e ) { - throw new MojoExecutionException( - "The site descriptor cannot interpolate properties: " + e.getMessage(), - e ); + throw new MojoExecutionException( "The site descriptor cannot interpolate properties: " + + e.getMessage(), e ); } decoration = readDecorationModel( siteDescriptorContent ); @@ -252,7 +252,8 @@ else { assembler.assembleModelInheritance( project.getName(), decoration, parent, project.getUrl(), - parentProject.getUrl() == null ? project.getUrl() : parentProject.getUrl() ); + parentProject.getUrl() == null ? project.getUrl() : parentProject + .getUrl() ); } if ( decoration != null ) { @@ -309,9 +310,10 @@ File result; // TODO: this is a bit crude - proper type, or proper handling as metadata rather than an artifact in 2.1? - Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(), project.getArtifactId(), - project.getVersion(), "xml", - "site_" + locale.getLanguage() ); + Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(), + project.getArtifactId(), + project.getVersion(), "xml", "site_" + + locale.getLanguage() ); boolean found = false; try @@ -370,46 +372,6 @@ return result; } - private File getSkinArtifactFile( DecorationModel decoration ) - throws MojoFailureException, MojoExecutionException - { - Skin skin = decoration.getSkin(); - - if ( skin == null ) - { - skin = Skin.getDefaultSkin(); - } - - String version = skin.getVersion(); - Artifact artifact; - try - { - if ( version == null ) - { - version = Artifact.RELEASE_VERSION; - } - VersionRange versionSpec = VersionRange.createFromVersionSpec( version ); - artifact = artifactFactory.createDependencyArtifact( skin.getGroupId(), skin.getArtifactId(), versionSpec, - "jar", null, null ); - - artifactResolver.resolve( artifact, repositories, localRepository ); - } - catch ( InvalidVersionSpecificationException e ) - { - throw new MojoFailureException( "The skin version '" + version + "' is not valid: " + e.getMessage() ); - } - catch ( ArtifactResolutionException e ) - { - throw new MojoExecutionException( "Unable to find skin", e ); - } - catch ( ArtifactNotFoundException e ) - { - throw new MojoFailureException( "The skin does not exist: " + e.getMessage() ); - } - - return artifact.getFile(); - } - protected List filterReports( List reports ) { List filteredReports = new ArrayList( reports.size() ); @@ -430,8 +392,9 @@ // plugins with an earlier version to fail (most of the org.codehaus mojo now fails) // be nice with them, output a warning and don't let them break anything - getLog().warn( "Error loading report " + report.getClass().getName() - + " - AbstractMethodError: canGenerateReport()" ); + getLog().warn( + "Error loading report " + report.getClass().getName() + + " - AbstractMethodError: canGenerateReport()" ); filteredReports.add( report ); } } @@ -477,7 +440,16 @@ } } - File skinFile = getSkinArtifactFile( decorationModel ); + File skinFile; + try + { + skinFile = siteTool.getSkinArtifactFromRepository( localRepository, repositories, decorationModel ) + .getFile(); + } + catch ( SiteToolException e ) + { + throw new MojoExecutionException( "SiteToolException: " + e.getMessage(), e ); + } SiteRenderingContext context; if ( templateFile != null ) { @@ -490,8 +462,8 @@ } else { - context = - siteRenderer.createContextForSkin( skinFile, attributes, decorationModel, project.getName(), locale ); + context = siteRenderer.createContextForSkin( skinFile, attributes, decorationModel, project.getName(), + locale ); } // Generate static site @@ -547,9 +519,8 @@ } catch ( IOException e ) { - throw new MojoExecutionException( - "The site descriptor cannot interpolate properties: " + e.getMessage(), - e ); + throw new MojoExecutionException( "The site descriptor cannot interpolate properties: " + + e.getMessage(), e ); } decorationModel = readDecorationModel( siteDescriptorContent ); @@ -588,8 +559,9 @@ { String displayLanguage = locale.getDisplayLanguage( Locale.ENGLISH ); - getLog().info( "Skipped \"" + report.getName( locale ) + "\" report, file \"" + outputName - + "\" already exists for the " + displayLanguage + " version." ); + getLog().info( + "Skipped \"" + report.getName( locale ) + "\" report, file \"" + outputName + + "\" already exists for the " + displayLanguage + " version." ); i.remove(); } else @@ -651,8 +623,8 @@ String title = i18n.getString( "site-plugin", locale, "report.information.title" ); String desc1 = i18n.getString( "site-plugin", locale, "report.information.description1" ); String desc2 = i18n.getString( "site-plugin", locale, "report.information.description2" ); - DocumentRenderer renderer = - new CategorySummaryDocumentRenderer( renderingContext, title, desc1, desc2, i18n, categoryReports ); + DocumentRenderer renderer = new CategorySummaryDocumentRenderer( renderingContext, title, desc1, desc2, + i18n, categoryReports ); if ( !documents.containsKey( renderer.getOutputName() ) ) { @@ -671,8 +643,8 @@ String title = i18n.getString( "site-plugin", locale, "report.project.title" ); String desc1 = i18n.getString( "site-plugin", locale, "report.project.description1" ); String desc2 = i18n.getString( "site-plugin", locale, "report.project.description2" ); - DocumentRenderer renderer = - new CategorySummaryDocumentRenderer( renderingContext, title, desc1, desc2, i18n, categoryReports ); + DocumentRenderer renderer = new CategorySummaryDocumentRenderer( renderingContext, title, desc1, desc2, + i18n, categoryReports ); if ( !documents.containsKey( renderer.getOutputName() ) ) { @@ -686,5 +658,3 @@ return documents; } } - -