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/01/23 01:08:16 UTC
svn commit: r614386 - in /maven/shared/trunk/maven-doxia-tools: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/maven/ src/main/java/org/apache/maven/doxia/
src/main/java/org/apache/maven/doxia/too...
Author: vsiveton
Date: Tue Jan 22 16:08:09 2008
New Revision: 614386
URL: http://svn.apache.org/viewvc?rev=614386&view=rev
Log:
MSITE-290: Move logic from AbstractSiteMojo and AbstractSiteRenderingMojo for Doxia related stuff
o first import from o.a.m.p.site:
- AbstractSiteMojo#getRelativePath( String to, String from )
- AbstractSiteRenderingMojo#getSkinArtifactFile( DecorationModel decoration )
Added:
maven/shared/trunk/maven-doxia-tools/pom.xml (with props)
maven/shared/trunk/maven-doxia-tools/src/
maven/shared/trunk/maven-doxia-tools/src/main/
maven/shared/trunk/maven-doxia-tools/src/main/java/
maven/shared/trunk/maven-doxia-tools/src/main/java/org/
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java (with props)
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java (with props)
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteToolException.java (with props)
maven/shared/trunk/maven-doxia-tools/src/test/
maven/shared/trunk/maven-doxia-tools/src/test/java/
maven/shared/trunk/maven-doxia-tools/src/test/java/org/
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java (with props)
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/stubs/
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java (with props)
maven/shared/trunk/maven-doxia-tools/src/test/resources/
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/pom.xml (with props)
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/site/
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/site/site.xml (with props)
Added: maven/shared/trunk/maven-doxia-tools/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/pom.xml?rev=614386&view=auto
==============================================================================
--- maven/shared/trunk/maven-doxia-tools/pom.xml (added)
+++ maven/shared/trunk/maven-doxia-tools/pom.xml Tue Jan 22 16:08:09 2008
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-components</artifactId>
+ <version>8</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-doxia-tools</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Maven Doxia Tools</name>
+
+ <prerequisites>
+ <maven>2.0.2</maven>
+ </prerequisites>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create-component-descriptor</id>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- maven -->
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ <version>2.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <version>2.0.2</version>
+ </dependency>
+
+ <!-- doxia-sitetools -->
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-decoration-model</artifactId>
+ <version>${doxia-sitetools.version}</version>
+ </dependency>
+
+ <!-- Plexus -->
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-archiver</artifactId>
+ <version>1.0-alpha-7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.4.5</version>
+ </dependency>
+
+ <!-- test -->
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <properties>
+ <doxia.version>1.0-alpha-10</doxia.version>
+ <doxia-sitetools.version>1.0-alpha-10</doxia-sitetools.version>
+ </properties>
+</project>
Propchange: maven/shared/trunk/maven-doxia-tools/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-doxia-tools/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java?rev=614386&view=auto
==============================================================================
--- maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java (added)
+++ maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java Tue Jan 22 16:08:09 2008
@@ -0,0 +1,341 @@
+package org.apache.maven.doxia.tools;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.doxia.site.decoration.DecorationModel;
+import org.apache.maven.doxia.site.decoration.Skin;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.doxia.tools.SiteTool" role-hint="default"
+ */
+public class DefaultSiteTool
+ extends AbstractLogEnabled
+ implements SiteTool
+{
+ // ----------------------------------------------------------------------
+ // Components
+ // ----------------------------------------------------------------------
+
+ /**
+ * The component that is used to resolve additional artifacts required.
+ *
+ * @plexus.requirement
+ */
+ private ArtifactResolver artifactResolver;
+
+ /**
+ * The component used for creating artifact instances.
+ *
+ * @plexus.requirement
+ */
+ private ArtifactFactory artifactFactory;
+
+ // ----------------------------------------------------------------------
+ // Public methods
+ // ----------------------------------------------------------------------
+
+ /** {@inheritDoc} */
+ public Artifact getSkinArtifactFromRepository( ArtifactRepository localRepository, List remoteArtifactRepositories,
+ DecorationModel decoration )
+ throws SiteToolException
+ {
+ if ( localRepository == null )
+ {
+ throw new IllegalArgumentException( "localRepository could not be null" );
+ }
+ if ( remoteArtifactRepositories == null )
+ {
+ throw new IllegalArgumentException( "remoteArtifactRepositories could not be null" );
+ }
+ if ( decoration == null )
+ {
+ throw new IllegalArgumentException( "decoration could not be null" );
+ }
+
+ 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, remoteArtifactRepositories, localRepository );
+ }
+ catch ( InvalidVersionSpecificationException e )
+ {
+ throw new SiteToolException( "InvalidVersionSpecificationException: The skin version '" + version
+ + "' is not valid: " + e.getMessage() );
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new SiteToolException( "ArtifactResolutionException: Unable to find skin", e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ throw new SiteToolException( "ArtifactNotFoundException: The skin does not exist: " + e.getMessage() );
+ }
+
+ return artifact;
+ }
+
+ /** {@inheritDoc} */
+ public Artifact getDefaultSkinArtifact( ArtifactRepository localRepository, List remoteArtifactRepositories )
+ throws SiteToolException
+ {
+ return getSkinArtifactFromRepository( localRepository, remoteArtifactRepositories, new DecorationModel() );
+ }
+
+ /** {@inheritDoc} */
+ public String getRelativePath( String to, String from )
+ {
+ if ( to == null )
+ {
+ throw new IllegalArgumentException( "to could not be null" );
+ }
+ if ( from == null )
+ {
+ throw new IllegalArgumentException( "from could not be null" );
+ }
+
+ 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 )
+ {
+ getLogger().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 )
+ {
+ getLogger().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 ) )
+ {
+ getLogger().debug( "Mapped url: " + to + " to relative path: " + relativePath );
+ }
+
+ return relativePath;
+ }
+}
Propchange: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java?rev=614386&view=auto
==============================================================================
--- maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java (added)
+++ maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java Tue Jan 22 16:08:09 2008
@@ -0,0 +1,79 @@
+package org.apache.maven.doxia.tools;
+
+/*
+ * 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.
+ */
+
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.doxia.site.decoration.DecorationModel;
+import org.apache.maven.doxia.site.decoration.Skin;
+
+/**
+ * This tool contains some utilities methods to play with Doxia <code>DecorationModel</code>.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public interface SiteTool
+{
+ /** Plexus Role */
+ String ROLE = SiteTool.class.getName();
+
+ /**
+ * @param localRepository not null
+ * @param remoteArtifactRepositories not null
+ * @param decoration not null
+ * @return the <code>Skin</code> artifact defined in a <code>DecorationModel</code> from a given project and a local repository
+ * @throws SiteToolException if any
+ */
+ Artifact getSkinArtifactFromRepository( ArtifactRepository localRepository, List remoteArtifactRepositories,
+ DecorationModel decoration )
+ throws SiteToolException;
+
+ /**
+ * @param localRepository not null
+ * @param remoteArtifactRepositories not null
+ * @param decoration not null
+ * @return the default <code>Skin</code> artifact from a given project and a local repository
+ * @throws SiteToolException if any
+ * @see Skin#getDefaultSkin()
+ */
+ Artifact getDefaultSkinArtifact( ArtifactRepository localRepository, List remoteArtifactRepositories )
+ throws SiteToolException;
+
+ /**
+ * For example:
+ * <dl>
+ * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org"</dl>
+ * <dd>return ""</dd>
+ * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org/plugins/maven-site-plugin/"</dl>
+ * <dd>return "../.."</dd>
+ * <dt>to = "http://maven.apache.org/plugins/maven-site-plugin/" and from = "http://maven.apache.org"</dl>
+ * <dd>return "plugins/maven-site-plugin"</dd>
+ * </dl>
+ * <b>Note</b>: The file separator depends on the system.
+ *
+ * @param to
+ * @param from
+ * @return a relative path from <code>from</code> to <code>to</code>.
+ */
+ String getRelativePath( String to, String from );
+}
Propchange: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteToolException.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteToolException.java?rev=614386&view=auto
==============================================================================
--- maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteToolException.java (added)
+++ maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteToolException.java Tue Jan 22 16:08:09 2008
@@ -0,0 +1,67 @@
+package org.apache.maven.doxia.tools;
+
+/*
+ * 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.
+ */
+
+/**
+ * An exception occurring during the execution of this tool.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class SiteToolException
+ extends Exception
+{
+ /** serialVersionUID */
+ static final long serialVersionUID = 2331441332996055959L;
+
+ /**
+ * Construct a new <code>SiteToolException</code> exception wrapping an underlying <code>Exception</code>
+ * and providing a <code>message</code>.
+ *
+ * @param message
+ * @param cause
+ */
+ public SiteToolException( String message, Exception cause )
+ {
+ super( message, cause );
+ }
+
+ /**
+ * Construct a new <code>SiteToolException</code> exception wrapping an underlying <code>Throwable</code>
+ * and providing a <code>message</code>.
+ *
+ * @param message
+ * @param cause
+ */
+ public SiteToolException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ /**
+ * Construct a new <code>SiteToolException</code> exception providing a <code>message</code>.
+ *
+ * @param message
+ */
+ public SiteToolException( String message )
+ {
+ super( message );
+ }
+}
Propchange: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteToolException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/SiteToolException.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java?rev=614386&view=auto
==============================================================================
--- maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java (added)
+++ maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java Tue Jan 22 16:08:09 2008
@@ -0,0 +1,125 @@
+package org.apache.maven.doxia.tools;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.doxia.site.decoration.DecorationModel;
+import org.apache.maven.doxia.site.decoration.Skin;
+import org.apache.maven.doxia.tools.stubs.SiteToolMavenProjectStub;
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class SiteToolTest
+ extends PlexusTestCase
+{
+ /** {@inheritDoc} */
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ }
+
+ /** {@inheritDoc} */
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ }
+
+ /**
+ * @throws Exception
+ */
+ protected ArtifactRepository getLocalRepo()
+ throws Exception
+ {
+ String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS;
+ String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
+ ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag,
+ checksumPolicyFlag );
+ ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag,
+ checksumPolicyFlag );
+ ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ ArtifactRepositoryLayout defaultArtifactRepositoryLayout = (ArtifactRepositoryLayout) lookup(
+ ArtifactRepositoryLayout.ROLE,
+ "default" );
+ return artifactRepositoryFactory.createArtifactRepository( "local", getTestFile( "target/local-repo" ).toURL()
+ .toString(), defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy );
+ }
+
+ /**
+ * @throws Exception
+ */
+ public void testGetDefaultSkinArtifact()
+ throws Exception
+ {
+ SiteTool tool = (SiteTool) lookup( SiteTool.ROLE );
+ assertNotNull( tool );
+
+ SiteToolMavenProjectStub project = new SiteToolMavenProjectStub();
+ assertNotNull( tool.getDefaultSkinArtifact( getLocalRepo(), project.getRemoteArtifactRepositories() ) );
+ }
+
+ /**
+ * @throws Exception
+ */
+ public void testGetSkinArtifactFromRepository()
+ throws Exception
+ {
+ SiteTool tool = (SiteTool) lookup( SiteTool.ROLE );
+ assertNotNull( tool );
+
+ SiteToolMavenProjectStub project = new SiteToolMavenProjectStub();
+ DecorationModel decorationModel = new DecorationModel();
+ Skin skin = new Skin();
+ skin.setGroupId( "org.apache.maven.skins" );
+ skin.setArtifactId( "maven-stylus-skin" );
+ decorationModel.setSkin( skin );
+ assertNotNull( tool.getSkinArtifactFromRepository( getLocalRepo(), project.getRemoteArtifactRepositories(),
+ decorationModel ) );
+ }
+
+ /**
+ * @throws Exception
+ */
+ public void testGetRelativePath()
+ throws Exception
+ {
+ SiteTool tool = (SiteTool) lookup( SiteTool.ROLE );
+ assertNotNull( tool );
+
+ String to = "http://maven.apache.org";
+ String from = "http://maven.apache.org";
+ assertEquals( tool.getRelativePath( to, from ), "" );
+ to = "http://maven.apache.org";
+ from = "http://maven.apache.org/plugins/maven-site-plugin/";
+ assertEquals( tool.getRelativePath( to, from ), ".." + File.separator + ".." );
+ to = "http://maven.apache.org/plugins/maven-site-plugin/";
+ from = "http://maven.apache.org";
+ assertEquals( tool.getRelativePath( to, from ), "plugins" + File.separator + "maven-site-plugin" );
+ }
+}
Propchange: maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java?rev=614386&view=auto
==============================================================================
--- maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java (added)
+++ maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java Tue Jan 22 16:08:09 2008
@@ -0,0 +1,123 @@
+package org.apache.maven.doxia.tools.stubs;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Reporting;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class SiteToolMavenProjectStub
+ extends MavenProjectStub
+{
+ private Build build;
+
+ private Reporting reporting;
+
+ public SiteToolMavenProjectStub()
+ {
+ MavenXpp3Reader pomReader = new MavenXpp3Reader();
+ Model model = null;
+
+ try
+ {
+ model = pomReader.read( new FileReader( new File( getBasedir(), "pom.xml" ) ) );
+ setModel( model );
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( e );
+ }
+
+ setGroupId( model.getGroupId() );
+ setArtifactId( model.getArtifactId() );
+ setVersion( model.getVersion() );
+ setName( model.getName() );
+ setUrl( model.getUrl() );
+ setPackaging( model.getPackaging() );
+
+ Build build = new Build();
+ build.setFinalName( model.getArtifactId() );
+ build.setDirectory( super.getBasedir() + "/target/test/unit/site-tool-test/target" );
+ build.setSourceDirectory( getBasedir() + "/src/main/java" );
+ build.setOutputDirectory( super.getBasedir() + "/target/test/unit/site-tool-test/target/classes" );
+ build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
+ build.setTestOutputDirectory( super.getBasedir() + "/target/test/unit/site-tool-test/target/test-classes" );
+ setBuild( build );
+
+ List compileSourceRoots = new ArrayList();
+ compileSourceRoots.add( getBasedir() + "/src/main/java" );
+ setCompileSourceRoots( compileSourceRoots );
+
+ List testCompileSourceRoots = new ArrayList();
+ testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
+ setTestCompileSourceRoots( testCompileSourceRoots );
+
+ reporting = new Reporting();
+ reporting.setOutputDirectory( super.getBasedir() + "/target/test/unit/site-tool-test/target/site" );
+ }
+
+ /** {@inheritDoc} */
+ public Build getBuild()
+ {
+ return build;
+ }
+
+ /** {@inheritDoc} */
+ public void setBuild( Build build )
+ {
+ this.build = build;
+ }
+
+ /** {@inheritDoc} */
+ public File getBasedir()
+ {
+ return new File( super.getBasedir() + "/src/test/resources/unit/site-tool-test" );
+ }
+
+ /** {@inheritDoc} */
+ public List getRemoteArtifactRepositories()
+ {
+ ArtifactRepository repository = new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
+ new DefaultRepositoryLayout() );
+
+ return Collections.singletonList( repository );
+ }
+
+ /** {@inheritDoc} */
+ public Reporting getReporting()
+ {
+ return this.reporting;
+ }
+}
Propchange: maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/pom.xml?rev=614386&view=auto
==============================================================================
--- maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/pom.xml (added)
+++ maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/pom.xml Tue Jan 22 16:08:09 2008
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>site-tool-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>dummy</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/site/site.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/site/site.xml?rev=614386&view=auto
==============================================================================
--- maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/site/site.xml (added)
+++ maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/site/site.xml Tue Jan 22 16:08:09 2008
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!--
+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.
+-->
+
+<project name="Maven Dummy Site">
+ <bannerLeft>
+ <name>Maven Site</name>
+ <src>http://maven.apache.org/images/apache-maven-project.png</src>
+ <href>http://maven.apache.org/</href>
+ </bannerLeft>
+ <bannerRight>
+ <src>http://maven.apache.org/images/maven-small.gif</src>
+ </bannerRight>
+ <skin>
+ <groupId>org.apache.maven.skins</groupId>
+ <artifactId>maven-stylus-skin</artifactId>
+ </skin>
+ <body>
+ <links>
+ <item name="Maven 2" href="http://maven.apache.org/maven2/"/>
+ </links>
+
+ <menu name="Overview">
+ <item name="Test" href="/test.html"/>
+ </menu>
+ ${reports}
+ </body>
+</project>
Propchange: maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/site/site.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/site-tool-test/src/site/site.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"