Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Moore committed May 4, 2012
1 parent f705490 commit 6a79fe7
Show file tree
Hide file tree
Showing 8 changed files with 1,053 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
target/
.settings/
.classpath
.project
logs/
*.log
velocity.log*
.tomcatplugin
*.dump
classes/
*.class
*jacoco.exec
*~
197 changes: 197 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<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>com.technophobia.substeps</groupId>
<artifactId>substeps-runner</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1</version>

<name>SubSteps Maven Runner</name>

<organization>
<name>Technophobia Ltd</name>
<url>www.technophobia.com/</url>
</organization>

<licenses>
<license>
<name>LGPL 3.0 license</name>
<url>http://www.opensource.org/licenses/lgpl-3.0.html</url>
<distribution>manual</distribution>
</license>
</licenses>

<developers>

<developer>
<id>ianmoore</id>
<name>Ian Moore</name>
<organization>Technophobia</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>

<developer>
<id>rorygibson</id>
<name>Rory Gibson</name>
<organization>Technophobia</organization>
<roles>
<role>developer</role>
</roles>
</developer>

<developer>
<id>davemoss</id>
<name>Dave Moss</name>
<organization>Technophobia</organization>
<roles>
<role>developer</role>
</roles>
</developer>

<developer>
<id>stuartforbes</id>
<name>Stu Forbes</name>
<organization>Technophobia</organization>
<roles>
<role>developer</role>
</roles>
</developer>

</developers>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3.RC2</hamcrest.version>
<guava.version>10.0</guava.version>
<mockito.version>1.9.0-rc1</mockito.version>
<substeps.version>0.0.1</substeps.version>
<maven.version>2.2.1</maven.version>

<nexus.snapshot.artifacts>internalsnapshots</nexus.snapshot.artifacts>
<nexus.release.artifacts>internalreleases</nexus.release.artifacts>
</properties>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<inherit>true</inherit>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.5.5</version>

<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

<dependencies>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0.9</version>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>1.0-beta-1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>

</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
</dependency>

<dependency>
<groupId>com.technophobia.substeps</groupId>
<artifactId>substeps-core</artifactId>
<version>${substeps.version}</version>
</dependency>


</dependencies>

<scm>
<connection>scm:git:git://github.com/technophobia/substeps-runner.git</connection>
</scm>



</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright Technophobia Ltd 2012
*
* This file is part of Substeps Maven Runner.
*
* Substeps Maven Runner is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Substeps Maven Runner is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Substeps. If not, see <http://www.gnu.org/licenses/>.
*/
package com.technophobia.substeps.mojo.runner;

// from http://maven.40175.n5.nabble.com/Adding-project-dependencies-and-generated-classes-to-classpath-of-my-plugin-td110119.html

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.codehaus.classworlds.ClassRealm;
import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter;
import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A custom ComponentConfigurator which adds the project's runtime classpath
* elements to the
*
* @author Brian Jackson
* @since Aug 1, 2008 3:04:17 PM
*
* @plexus.component
* role="org.codehaus.plexus.component.configurator.ComponentConfigurator"
* role-hint="include-project-dependencies"
* @plexus.requirement role=
* "org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup"
* role-hint="default"
*/
public class IncludeProjectDependenciesComponentConfigurator extends AbstractComponentConfigurator {

private static final Logger LOGGER = LoggerFactory
.getLogger(IncludeProjectDependenciesComponentConfigurator.class);


@Override
public void configureComponent(final Object component, final PlexusConfiguration configuration,
final ExpressionEvaluator expressionEvaluator, final ClassRealm containerRealm,
final ConfigurationListener listener) throws ComponentConfigurationException {

addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm);

converterLookup.registerConverter(new ClassRealmConverter(containerRealm));

final ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter();

converter.processConfiguration(converterLookup, component, containerRealm.getClassLoader(),
configuration, expressionEvaluator, listener);
}


private void addProjectDependenciesToClassRealm(final ExpressionEvaluator expressionEvaluator,
final ClassRealm containerRealm) throws ComponentConfigurationException {
List<String> runtimeClasspathElements;

List<String> testClasspathElements;
try {
// noinspection unchecked
runtimeClasspathElements = (List<String>) expressionEvaluator
.evaluate("${project.runtimeClasspathElements}");

testClasspathElements = (List<String>) expressionEvaluator
.evaluate("${project.testClasspathElements}");

} catch (final ExpressionEvaluationException e) {
throw new ComponentConfigurationException(
"There was a problem evaluating: ${project.runtimeClasspathElements}", e);
}

runtimeClasspathElements.addAll(testClasspathElements);

Collections.reverse(runtimeClasspathElements);

// Add the project dependencies to the ClassRealm
final URL[] urls = buildURLs(runtimeClasspathElements);
for (final URL url : urls) {
containerRealm.addConstituent(url);
}
}


private URL[] buildURLs(final List<String> runtimeClasspathElements)
throws ComponentConfigurationException {
// Add the projects classes and dependencies
final List<URL> urls = new ArrayList<URL>(runtimeClasspathElements.size());
for (final String element : runtimeClasspathElements) {
try {
final URL url = new File(element).toURI().toURL();
urls.add(url);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Added to project class loader: " + url);
}
} catch (final MalformedURLException e) {
throw new ComponentConfigurationException("Unable to access project dependency: "
+ element, e);
}
}

// Add the plugin's dependencies (so Trove stuff works if Trove isn't on
return urls.toArray(new URL[urls.size()]);
}

}
Loading

0 comments on commit 6a79fe7

Please sign in to comment.