You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by ol...@apache.org on 2012/10/01 22:57:52 UTC
svn commit: r1392595 [14/15] - in /directmemory/lightning/trunk: ./
lightning-api/ lightning-api/src/ lightning-api/src/main/
lightning-api/src/main/java/ lightning-api/src/main/java/org/
lightning-api/src/main/java/org/apache/ lightning-api/src/main/j...
Added: directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/MavenGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/MavenGeneratorTestCase.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/MavenGeneratorTestCase.java (added)
+++ directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/MavenGeneratorTestCase.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+package org.apache.directmemory.lightning.maven.integration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.nio.charset.Charset;
+
+import org.junit.Test;
+
+public class MavenGeneratorTestCase
+{
+
+ @Test
+ public void testGeneration()
+ throws Exception
+ {
+ File target = new File( "target/classes" );
+ assertTrue( recursiveSearchClassFile( "FooLightningGeneratedMarshaller.class", target ) );
+
+ File testfile = new File( getClass().getClassLoader().getResource( "generated.java.out" ).toURI() );
+ File generatedFile =
+ new File(
+ "target/generated-sources/lightning/org/apache/directmemory/lightning/maven/integration/FooLightningGeneratedMarshaller.java" );
+ String expected = SupportUtil.readAllText( testfile, Charset.forName( "UTF-8" ) );
+ String result = SupportUtil.readAllText( generatedFile, Charset.forName( "UTF-8" ) );
+ assertEquals( expected, result );
+ }
+
+ private boolean recursiveSearchClassFile( String classFile, File path )
+ {
+ if ( path.isFile() && path.getName().equals( classFile ) )
+ {
+ return true;
+ }
+
+ if ( path.isDirectory() )
+ {
+ for ( File childPath : path.listFiles() )
+ {
+ if ( recursiveSearchClassFile( classFile, childPath ) )
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/MavenGeneratorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/MavenGeneratorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/SupportUtil.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/SupportUtil.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/SupportUtil.java (added)
+++ directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/SupportUtil.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+package org.apache.directmemory.lightning.maven.integration;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+
+public final class SupportUtil
+{
+
+ private SupportUtil()
+ {
+ }
+
+ public static List<File> recursiveGetAllJavaSources( File file, ArrayList<File> list, FileFilter fileFilter )
+ {
+ if ( file.isDirectory() )
+ {
+ for ( File f : file.listFiles( fileFilter ) )
+ {
+ recursiveGetAllJavaSources( f, list, fileFilter );
+ }
+ }
+ else
+ {
+ list.add( file );
+ }
+ return list;
+ }
+
+ public static String readAllText( File file, Charset charset )
+ {
+ try
+ {
+ StringBuilder sb = new StringBuilder();
+ LineNumberReader reader = new LineNumberReader( new FileReader( file ) );
+ String line = null;
+ while ( ( line = reader.readLine() ) != null )
+ {
+ sb.append( line );
+ }
+ return sb.toString();
+ }
+ catch ( IOException e )
+ {
+ return null;
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/SupportUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-integration-test/src/test/java/org/apache/directmemory/lightning/maven/integration/SupportUtil.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-maven-integration-test/src/test/resources/generated.java.out
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-integration-test/src/test/resources/generated.java.out?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-integration-test/src/test/resources/generated.java.out (added)
+++ directmemory/lightning/trunk/lightning-maven-integration-test/src/test/resources/generated.java.out Mon Oct 1 20:57:42 2012
@@ -0,0 +1,91 @@
+
+package org.apache.directmemory.lightning.maven.integration;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directmemory.lightning.Marshaller;
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiatorFactory;
+import org.apache.directmemory.lightning.internal.ClassDescriptorAwareSerializer;
+import org.apache.directmemory.lightning.internal.generator.AbstractGeneratedMarshaller;
+import org.apache.directmemory.lightning.metadata.ValuePropertyAccessor;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public final class FooLightningGeneratedMarshaller extends AbstractGeneratedMarshaller {
+
+ private final PropertyDescriptor DESCRIPTOR_BAR_LIGHTNING;
+ private final Marshaller MARSHALLER_BAR_LIGHTNING;
+ private final ValuePropertyAccessor ACCESSOR_BAR_LIGHTNING;
+ private final PropertyDescriptor DESCRIPTOR_FOO_LIGHTNING;
+ private final Marshaller MARSHALLER_FOO_LIGHTNING;
+ private final ValuePropertyAccessor ACCESSOR_FOO_LIGHTNING;
+
+ public FooLightningGeneratedMarshaller (Class<?> marshalledType, Map<Class<?>, Marshaller> marshallers,
+ ClassDescriptorAwareSerializer serializer, ObjectInstantiatorFactory objectInstantiatorFactory,
+ List<PropertyDescriptor> propertyDescriptors) {
+
+ super(marshalledType, marshallers, serializer, objectInstantiatorFactory);
+ DESCRIPTOR_BAR_LIGHTNING = propertyDescriptors.get(0);
+
+ PropertyDescriptor bar = findPropertyDescriptor("bar", propertyDescriptors);
+ Marshaller barMarshaller = bar.getMarshaller();
+ if (barMarshaller == null) {
+ barMarshaller = findMarshaller(bar);
+ }
+ MARSHALLER_BAR_LIGHTNING = barMarshaller;
+
+ ACCESSOR_BAR_LIGHTNING = (ValuePropertyAccessor) getPropertyAccessor("bar");
+ DESCRIPTOR_FOO_LIGHTNING = propertyDescriptors.get(1);
+
+ PropertyDescriptor foo = findPropertyDescriptor("foo", propertyDescriptors);
+ Marshaller fooMarshaller = foo.getMarshaller();
+ if (fooMarshaller == null) {
+ fooMarshaller = findMarshaller(foo);
+ }
+ MARSHALLER_FOO_LIGHTNING = fooMarshaller;
+
+ ACCESSOR_FOO_LIGHTNING = (ValuePropertyAccessor) getPropertyAccessor("foo");
+ }
+
+ public void marshall(Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput, SerializationContext serializationContext) throws IOException {
+ if (isAlreadyMarshalled(value, propertyDescriptor.getType(), dataOutput, serializationContext)) {
+ return;
+ }
+
+ ValuePropertyAccessor barPropertyAccessor = this.ACCESSOR_BAR_LIGHTNING;
+ PropertyDescriptor barPropertyDescriptor = this.DESCRIPTOR_BAR_LIGHTNING;
+ this.MARSHALLER_BAR_LIGHTNING.marshall(Integer.valueOf(barPropertyAccessor.readInt(value)), barPropertyDescriptor, dataOutput, serializationContext);
+
+ ValuePropertyAccessor fooPropertyAccessor = this.ACCESSOR_FOO_LIGHTNING;
+ PropertyDescriptor fooPropertyDescriptor = this.DESCRIPTOR_FOO_LIGHTNING;
+ this.MARSHALLER_FOO_LIGHTNING.marshall(fooPropertyAccessor.readObject(value), fooPropertyDescriptor, dataOutput, serializationContext);
+
+ }
+
+ public <V> V unmarshall(V instance, PropertyDescriptor propertyDescriptor, DataInput dataInput, SerializationContext serializationContext) throws IOException {
+ ValuePropertyAccessor barPropertyAccessor = this.ACCESSOR_BAR_LIGHTNING;
+ PropertyDescriptor barPropertyDescriptor = this.DESCRIPTOR_BAR_LIGHTNING;
+ Object barValue = this.MARSHALLER_BAR_LIGHTNING.unmarshall(barPropertyDescriptor, dataInput, serializationContext);
+ barPropertyAccessor.writeInt(instance, ((Integer) barValue).intValue());
+
+ ValuePropertyAccessor fooPropertyAccessor = this.ACCESSOR_FOO_LIGHTNING;
+ PropertyDescriptor fooPropertyDescriptor = this.DESCRIPTOR_FOO_LIGHTNING;
+ Object fooValue = this.MARSHALLER_FOO_LIGHTNING.unmarshall(fooPropertyDescriptor, dataInput, serializationContext);
+ fooPropertyAccessor.writeObject(instance, fooValue);
+
+ return instance;
+ }
+
+ private PropertyDescriptor findPropertyDescriptor(String propertyName, List<PropertyDescriptor> propertyDescriptors) {
+ for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+ if (propertyDescriptor.getPropertyName().equals(propertyName)) {
+ return propertyDescriptor;
+ }
+ }
+ return null;
+ }
+}
Added: directmemory/lightning/trunk/lightning-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-plugin/pom.xml?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-plugin/pom.xml (added)
+++ directmemory/lightning/trunk/lightning-maven-plugin/pom.xml Mon Oct 1 20:57:42 2012
@@ -0,0 +1,123 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>lightning-maven-plugin</artifactId>
+ <name>Lightning: Maven Plugin</name>
+ <packaging>maven-plugin</packaging>
+
+ <parent>
+ <artifactId>lightning-reactor</artifactId>
+ <groupId>org.apache.directmemory.lightning</groupId>
+ <version>0.0.1-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>lightning-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>lightning-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ow2.asm</groupId>
+ <artifactId>asm</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-compiler-api</artifactId>
+ <version>1.8.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-compiler-manager</artifactId>
+ <version>1.8.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-compiler-javac</artifactId>
+ <version>1.8.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven.plugin-testing</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ </build>
+</project>
\ No newline at end of file
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/AbstractCompilerMojo.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/AbstractCompilerMojo.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/AbstractCompilerMojo.java (added)
+++ directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/AbstractCompilerMojo.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,786 @@
+/*
+ * 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.
+ */
+package org.apache.directmemory.lightning.maven;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.compiler.Compiler;
+import org.codehaus.plexus.compiler.CompilerConfiguration;
+import org.codehaus.plexus.compiler.CompilerError;
+import org.codehaus.plexus.compiler.CompilerException;
+import org.codehaus.plexus.compiler.CompilerOutputStyle;
+import org.codehaus.plexus.compiler.manager.CompilerManager;
+import org.codehaus.plexus.compiler.manager.NoSuchCompilerException;
+import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
+import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
+import org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping;
+import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
+import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * TODO: At least one step could be optimized, currently the plugin will do two scans of all the source code if the
+ * compiler has to have the entire set of sources. This is currently the case for at least the C# compiler and most
+ * likely all the other .NET compilers too.
+ *
+ * @author others
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
+ * @version $Id$
+ * @since 2.0
+ */
+public abstract class AbstractCompilerMojo
+ extends AbstractMojo
+{
+
+ // ----------------------------------------------------------------------
+ // Configurables
+ // ----------------------------------------------------------------------
+
+ /**
+ * Indicates whether the build will continue even if there are compilation errors; defaults to true.
+ *
+ * @parameter expression="${maven.compiler.failOnError}" default-value="true"
+ * @since 2.0.2
+ */
+ private boolean failOnError = true;
+
+ /**
+ * Set to true to include debugging information in the compiled class files.
+ *
+ * @parameter expression="${maven.compiler.debug}" default-value="true"
+ */
+ private boolean debug = true;
+
+ /**
+ * Set to true to show messages about what the compiler is doing.
+ *
+ * @parameter expression="${maven.compiler.verbose}" default-value="false"
+ */
+ private boolean verbose;
+
+ /**
+ * Sets whether to show source locations where deprecated APIs are used.
+ *
+ * @parameter expression="${maven.compiler.showDeprecation}" default-value="false"
+ */
+ private boolean showDeprecation;
+
+ /**
+ * Set to true to optimize the compiled code using the compiler's optimization methods.
+ *
+ * @parameter expression="${maven.compiler.optimize}" default-value="false"
+ */
+ private boolean optimize;
+
+ /**
+ * Set to true to show compilation warnings.
+ *
+ * @parameter expression="${maven.compiler.showWarnings}" default-value="false"
+ */
+ private boolean showWarnings;
+
+ /**
+ * The -source argument for the Java compiler.
+ *
+ * @parameter expression="${maven.compiler.source}" default-value="1.5"
+ */
+ protected String source;
+
+ /**
+ * The -target argument for the Java compiler.
+ *
+ * @parameter expression="${maven.compiler.target}" default-value="1.5"
+ */
+ protected String target;
+
+ /**
+ * The -encoding argument for the Java compiler.
+ *
+ * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
+ */
+ protected String encoding;
+
+ /**
+ * Sets the granularity in milliseconds of the last modification date for testing whether a source needs
+ * recompilation.
+ *
+ * @parameter expression="${lastModGranularityMs}" default-value="0"
+ */
+ private int staleMillis;
+
+ /**
+ * The compiler id of the compiler to use. See this <a href="non-javac-compilers.html">guide</a> for more
+ * information.
+ *
+ * @parameter expression="${maven.compiler.compilerId}" default-value="javac"
+ */
+ private String compilerId;
+
+ /**
+ * Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true.
+ *
+ * @parameter expression="${maven.compiler.compilerVersion}"
+ */
+ private String compilerVersion;
+
+ /**
+ * Allows running the compiler in a separate process. If "false" it uses the built in compiler, while if "true" it
+ * will use an executable.
+ *
+ * @parameter expression="${maven.compiler.fork}" default-value="false"
+ */
+ private boolean fork;
+
+ /**
+ * Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" if fork is set to true.
+ *
+ * @parameter expression="${maven.compiler.meminitial}"
+ * @since 2.0.1
+ */
+ private String meminitial;
+
+ /**
+ * Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" if fork is set to true.
+ *
+ * @parameter expression="${maven.compiler.maxmem}"
+ * @since 2.0.1
+ */
+ private String maxmem;
+
+ /**
+ * Sets the executable of the compiler to use when fork is true.
+ *
+ * @parameter expression="${maven.compiler.executable}"
+ */
+ private String executable;
+
+ /**
+ * <p>
+ * Sets whether annotation processing is performed or not. Only applies to JDK 1.6+ If not set, both compilation and
+ * annotation processing are performed at the same time.
+ * </p>
+ * <p>
+ * Allowed values are: none - no annotation processing is performed. only - only annotation processing is done, no
+ * compilation.
+ * </p>
+ *
+ * @parameter
+ * @since 2.2
+ */
+ private String proc;
+
+ /**
+ * <p>
+ * Names of annotation processors to run. Only applies to JDK 1.6+ If not set, the default annotation processors
+ * discovery process applies.
+ * </p>
+ *
+ * @parameter
+ * @since 2.2
+ */
+ private String[] annotationProcessors;
+
+ /**
+ * <p>
+ * Sets the arguments to be passed to the compiler (prepending a dash) if fork is set to true.
+ * </p>
+ * <p>
+ * This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.
+ * </p>
+ *
+ * @parameter
+ * @since 2.0.1
+ */
+ protected Map<String, String> compilerArguments;
+
+ /**
+ * <p>
+ * Sets the unformatted argument string to be passed to the compiler if fork is set to true.
+ * </p>
+ * <p>
+ * This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.
+ * </p>
+ *
+ * @parameter
+ */
+ protected String compilerArgument;
+
+ /**
+ * Sets the name of the output file when compiling a set of sources to a single file.
+ *
+ * @parameter expression="${project.build.finalName}"
+ */
+ private String outputFileName;
+
+ /**
+ * Keyword list to be appended to the -g command-line switch. Legal values are none or a comma-separated list of the
+ * following keywords: lines, vars, and source. If debuglevel is not specified, by default, nothing will be appended
+ * to -g. If debug is not turned on, this attribute will be ignored.
+ *
+ * @parameter expression="${maven.compiler.debuglevel}"
+ * @since 2.1
+ */
+ private String debuglevel;
+
+ /** @component */
+ private ToolchainManager toolchainManager;
+
+ // ----------------------------------------------------------------------
+ // Read-only parameters
+ // ----------------------------------------------------------------------
+
+ /**
+ * The directory to run the compiler from if fork is true.
+ *
+ * @parameter default-value="${basedir}"
+ * @required
+ * @readonly
+ */
+ private File basedir;
+
+ /**
+ * The target directory of the compiler if fork is true.
+ *
+ * @parameter default-value="${project.build.directory}"
+ * @required
+ * @readonly
+ */
+ private File buildDirectory;
+
+ /**
+ * Plexus compiler manager.
+ *
+ * @component
+ */
+ private CompilerManager compilerManager;
+
+ /**
+ * The current build session instance. This is used for toolchain manager API calls.
+ *
+ * @parameter default-value="${session}"
+ * @required
+ * @readonly
+ */
+ private MavenSession session;
+
+ protected abstract SourceInclusionScanner getSourceInclusionScanner( int staleMillis );
+
+ protected abstract SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding );
+
+ protected abstract List<String> getClasspathElements();
+
+ protected abstract List<String> getCompileSourceRoots();
+
+ protected abstract File getOutputDirectory();
+
+ protected abstract String getSource();
+
+ protected abstract String getTarget();
+
+ protected abstract String getCompilerArgument();
+
+ protected abstract Map<String, String> getCompilerArguments();
+
+ protected abstract File getGeneratedSourcesDirectory();
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public void execute()
+ throws MojoExecutionException, CompilationFailureException
+ {
+ // ----------------------------------------------------------------------
+ // Look up the compiler. This is done before other code than can
+ // cause the mojo to return before the lookup is done possibly resulting
+ // in misconfigured POMs still building.
+ // ----------------------------------------------------------------------
+
+ Compiler compiler;
+
+ getLog().debug( "Using compiler '" + compilerId + "'." );
+
+ try
+ {
+ compiler = compilerManager.getCompiler( compilerId );
+ }
+ catch ( NoSuchCompilerException e )
+ {
+ throw new MojoExecutionException( "No such compiler '" + e.getCompilerId() + "'." );
+ }
+
+ // -----------toolchains start here ----------------------------------
+ // use the compilerId as identifier for toolchains as well.
+ Toolchain tc = getToolchain();
+ if ( tc != null )
+ {
+ getLog().info( "Toolchain in compiler-plugin: " + tc );
+ if ( executable != null )
+ {
+ getLog().warn( "Toolchains are ignored, 'executable' parameter is set to " + executable );
+ }
+ else
+ {
+ fork = true;
+ // TODO somehow shaky dependency between compilerId and tool
+ // executable.
+ executable = tc.findTool( compilerId );
+ }
+ }
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ List<String> compileSourceRoots = removeEmptyCompileSourceRoots( getCompileSourceRoots() );
+
+ if ( compileSourceRoots.isEmpty() )
+ {
+ getLog().info( "No sources to compile" );
+
+ return;
+ }
+
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Source directories: " + compileSourceRoots.toString().replace( ',', '\n' ) );
+ getLog().debug( "Classpath: " + getClasspathElements().toString().replace( ',', '\n' ) );
+ getLog().debug( "Output directory: " + getOutputDirectory() );
+ }
+
+ // ----------------------------------------------------------------------
+ // Create the compiler configuration
+ // ----------------------------------------------------------------------
+
+ CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
+
+ compilerConfiguration.setOutputLocation( getOutputDirectory().getAbsolutePath() );
+
+ compilerConfiguration.setClasspathEntries( getClasspathElements() );
+
+ compilerConfiguration.setSourceLocations( compileSourceRoots );
+
+ compilerConfiguration.setOptimize( optimize );
+
+ compilerConfiguration.setDebug( debug );
+
+ if ( debug && StringUtils.isNotEmpty( debuglevel ) )
+ {
+ String[] split = StringUtils.split( debuglevel, "," );
+ for ( int i = 0; i < split.length; i++ )
+ {
+ if ( !( split[i].equalsIgnoreCase( "none" ) || split[i].equalsIgnoreCase( "lines" )
+ || split[i].equalsIgnoreCase( "vars" ) || split[i].equalsIgnoreCase( "source" ) ) )
+ {
+ throw new IllegalArgumentException( "The specified debug level: '" + split[i]
+ + "' is unsupported. " + "Legal values are 'none', 'lines', 'vars', and 'source'." );
+ }
+ }
+ compilerConfiguration.setDebugLevel( debuglevel );
+ }
+
+ compilerConfiguration.setVerbose( verbose );
+
+ compilerConfiguration.setShowWarnings( showWarnings );
+
+ compilerConfiguration.setShowDeprecation( showDeprecation );
+
+ compilerConfiguration.setSourceVersion( getSource() );
+
+ compilerConfiguration.setTargetVersion( getTarget() );
+
+ compilerConfiguration.setProc( proc );
+
+ compilerConfiguration.setGeneratedSourcesDirectory( getGeneratedSourcesDirectory() );
+
+ compilerConfiguration.setAnnotationProcessors( annotationProcessors );
+
+ compilerConfiguration.setSourceEncoding( encoding );
+
+ Map<String, String> effectiveCompilerArguments = getCompilerArguments();
+
+ String effectiveCompilerArgument = getCompilerArgument();
+
+ if ( ( effectiveCompilerArguments != null ) || ( effectiveCompilerArgument != null ) )
+ {
+ LinkedHashMap<String, String> cplrArgsCopy = new LinkedHashMap<String, String>();
+ if ( effectiveCompilerArguments != null )
+ {
+ for ( Map.Entry<String, String> me : effectiveCompilerArguments.entrySet() )
+ {
+ String key = me.getKey();
+ String value = me.getValue();
+ if ( !key.startsWith( "-" ) )
+ {
+ key = "-" + key;
+ }
+ cplrArgsCopy.put( key, value );
+ }
+ }
+ if ( !StringUtils.isEmpty( effectiveCompilerArgument ) )
+ {
+ cplrArgsCopy.put( effectiveCompilerArgument, null );
+ }
+ compilerConfiguration.setCustomCompilerArguments( cplrArgsCopy );
+ }
+
+ compilerConfiguration.setFork( fork );
+
+ if ( fork )
+ {
+ if ( !StringUtils.isEmpty( meminitial ) )
+ {
+ String value = getMemoryValue( meminitial );
+
+ if ( value != null )
+ {
+ compilerConfiguration.setMeminitial( value );
+ }
+ else
+ {
+ getLog().info( "Invalid value for meminitial '" + meminitial + "'. Ignoring this option." );
+ }
+ }
+
+ if ( !StringUtils.isEmpty( maxmem ) )
+ {
+ String value = getMemoryValue( maxmem );
+
+ if ( value != null )
+ {
+ compilerConfiguration.setMaxmem( value );
+ }
+ else
+ {
+ getLog().info( "Invalid value for maxmem '" + maxmem + "'. Ignoring this option." );
+ }
+ }
+ }
+
+ compilerConfiguration.setExecutable( executable );
+
+ compilerConfiguration.setWorkingDirectory( basedir );
+
+ compilerConfiguration.setCompilerVersion( compilerVersion );
+
+ compilerConfiguration.setBuildDirectory( buildDirectory );
+
+ compilerConfiguration.setOutputFileName( outputFileName );
+
+ // TODO: have an option to always compile (without need to clean)
+ Set<File> staleSources;
+
+ boolean canUpdateTarget;
+
+ try
+ {
+ staleSources =
+ computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( staleMillis ) );
+
+ canUpdateTarget = compiler.canUpdateTarget( compilerConfiguration );
+
+ if ( compiler.getCompilerOutputStyle().equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES )
+ && !canUpdateTarget )
+ {
+ getLog().info( "RESCANNING!" );
+ // TODO: This second scan for source files is sub-optimal
+ String inputFileEnding = compiler.getInputFileEnding( compilerConfiguration );
+
+ Set<File> sources =
+ computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( inputFileEnding ) );
+
+ compilerConfiguration.setSourceFiles( sources );
+ }
+ else
+ {
+ compilerConfiguration.setSourceFiles( staleSources );
+ }
+ }
+ catch ( CompilerException e )
+ {
+ throw new MojoExecutionException( "Error while computing stale sources.", e );
+ }
+
+ if ( staleSources.isEmpty() )
+ {
+ getLog().info( "Nothing to compile - all classes are up to date" );
+
+ return;
+ }
+
+ // ----------------------------------------------------------------------
+ // Dump configuration
+ // ----------------------------------------------------------------------
+
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Classpath:" );
+
+ for ( String s : getClasspathElements() )
+ {
+ getLog().debug( " " + s );
+ }
+
+ getLog().debug( "Source roots:" );
+
+ for ( String root : getCompileSourceRoots() )
+ {
+ getLog().debug( " " + root );
+ }
+
+ try
+ {
+ if ( fork )
+ {
+ if ( compilerConfiguration.getExecutable() != null )
+ {
+ getLog().debug( "Excutable: " );
+ getLog().debug( " " + compilerConfiguration.getExecutable() );
+ }
+ }
+
+ String[] cl = compiler.createCommandLine( compilerConfiguration );
+ if ( cl != null && cl.length > 0 )
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append( cl[0] );
+ for ( int i = 1; i < cl.length; i++ )
+ {
+ sb.append( " " );
+ sb.append( cl[i] );
+ }
+ getLog().debug( "Command line options:" );
+ getLog().debug( sb );
+ }
+ }
+ catch ( CompilerException ce )
+ {
+ getLog().debug( ce );
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // Compile!
+ // ----------------------------------------------------------------------
+
+ if ( StringUtils.isEmpty( compilerConfiguration.getSourceEncoding() ) )
+ {
+ getLog().warn( "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING
+ + ", i.e. build is platform dependent!" );
+ }
+
+ List<CompilerError> messages;
+
+ try
+ {
+ messages = compiler.compile( compilerConfiguration );
+ }
+ catch ( Exception e )
+ {
+ // TODO: don't catch Exception
+ throw new MojoExecutionException( "Fatal error compiling", e );
+ }
+
+ List<CompilerError> warnings = new ArrayList<CompilerError>();
+ List<CompilerError> errors = new ArrayList<CompilerError>();
+ if ( messages != null )
+ {
+ for ( CompilerError message : messages )
+ {
+ if ( message.isError() )
+ {
+ errors.add( message );
+ }
+ else
+ {
+ warnings.add( message );
+ }
+ }
+ }
+
+ if ( failOnError && !errors.isEmpty() )
+ {
+ if ( !warnings.isEmpty() )
+ {
+ getLog().info( "-------------------------------------------------------------" );
+ getLog().warn( "COMPILATION WARNING : " );
+ getLog().info( "-------------------------------------------------------------" );
+ for ( CompilerError warning : warnings )
+ {
+ getLog().warn( warning.toString() );
+ }
+ getLog().info( warnings.size() + ( ( warnings.size() > 1 ) ? " warnings " : " warning" ) );
+ getLog().info( "-------------------------------------------------------------" );
+ }
+
+ getLog().info( "-------------------------------------------------------------" );
+ getLog().error( "COMPILATION ERROR : " );
+ getLog().info( "-------------------------------------------------------------" );
+
+ for ( CompilerError error : errors )
+ {
+ getLog().error( error.toString() );
+ }
+ getLog().info( errors.size() + ( ( errors.size() > 1 ) ? " errors " : " error" ) );
+ getLog().info( "-------------------------------------------------------------" );
+
+ throw new CompilationFailureException( errors );
+ }
+ else
+ {
+ for ( CompilerError message : messages )
+ {
+ getLog().warn( message.toString() );
+ }
+ }
+ }
+
+ private String getMemoryValue( String setting )
+ {
+ String value = null;
+
+ // Allow '128' or '128m'
+ if ( isDigits( setting ) )
+ {
+ value = setting + "m";
+ }
+ else
+ {
+ if ( ( isDigits( setting.substring( 0, setting.length() - 1 ) ) )
+ && ( setting.toLowerCase().endsWith( "m" ) ) )
+ {
+ value = setting;
+ }
+ }
+ return value;
+ }
+
+ // TODO remove the part with ToolchainManager lookup once we depend on
+ // 3.0.9 (have it as prerequisite). Define as regular component field then.
+ private Toolchain getToolchain()
+ {
+ Toolchain tc = null;
+ if ( toolchainManager != null )
+ {
+ tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
+ }
+ return tc;
+ }
+
+ private boolean isDigits( String string )
+ {
+ for ( int i = 0; i < string.length(); i++ )
+ {
+ if ( !Character.isDigit( string.charAt( i ) ) )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private Set<File> computeStaleSources( CompilerConfiguration compilerConfiguration, Compiler compiler,
+ SourceInclusionScanner scanner )
+ throws MojoExecutionException, CompilerException
+ {
+ CompilerOutputStyle outputStyle = compiler.getCompilerOutputStyle();
+
+ SourceMapping mapping;
+
+ File outputDirectory;
+
+ if ( outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE )
+ {
+ mapping =
+ new SuffixMapping( compiler.getInputFileEnding( compilerConfiguration ),
+ compiler.getOutputFileEnding( compilerConfiguration ) );
+
+ outputDirectory = getOutputDirectory();
+ }
+ else if ( outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES )
+ {
+ mapping =
+ new SingleTargetSourceMapping( compiler.getInputFileEnding( compilerConfiguration ),
+ compiler.getOutputFile( compilerConfiguration ) );
+
+ outputDirectory = buildDirectory;
+ }
+ else
+ {
+ throw new MojoExecutionException( "Unknown compiler output style: '" + outputStyle + "'." );
+ }
+
+ scanner.addSourceMapping( mapping );
+
+ Set<File> staleSources = new HashSet<File>();
+
+ for ( String sourceRoot : getCompileSourceRoots() )
+ {
+ File rootFile = new File( sourceRoot );
+
+ if ( !rootFile.isDirectory() )
+ {
+ continue;
+ }
+
+ try
+ {
+ staleSources.addAll( scanner.getIncludedSources( rootFile, outputDirectory ) );
+ }
+ catch ( InclusionScanException e )
+ {
+ throw new MojoExecutionException( "Error scanning source root: \'" + sourceRoot + "\' "
+ + "for stale files to recompile.", e );
+ }
+ }
+
+ return staleSources;
+ }
+
+ /**
+ * @todo also in ant plugin. This should be resolved at some point so that it does not need to be calculated
+ * continuously - or should the plugins accept empty source roots as is?
+ */
+ private static List<String> removeEmptyCompileSourceRoots( List<String> compileSourceRootsList )
+ {
+ List<String> newCompileSourceRootsList = new ArrayList<String>();
+ if ( compileSourceRootsList != null )
+ {
+ // copy as I may be modifying it
+ for ( String srcDir : compileSourceRootsList )
+ {
+ if ( !newCompileSourceRootsList.contains( srcDir ) && new File( srcDir ).exists() )
+ {
+ newCompileSourceRootsList.add( srcDir );
+ }
+ }
+ }
+ return newCompileSourceRootsList;
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/AbstractCompilerMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/AbstractCompilerMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/CompilationFailureException.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/CompilationFailureException.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/CompilationFailureException.java (added)
+++ directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/CompilationFailureException.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+package org.apache.directmemory.lightning.maven;
+
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.compiler.CompilerError;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @version $Id$
+ * @since 2.0
+ */
+@SuppressWarnings( "serial" )
+public class CompilationFailureException
+ extends MojoFailureException
+{
+
+ private static final String LS = System.getProperty( "line.separator" );
+
+ public CompilationFailureException( List<CompilerError> messages )
+ {
+ super( null, shortMessage( messages ), longMessage( messages ) );
+ }
+
+ public static String longMessage( List<CompilerError> messages )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ if ( messages != null )
+ {
+ for ( CompilerError compilerError : messages )
+ {
+ sb.append( compilerError ).append( LS );
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Short message will have the error message if there's only one, useful for errors forking the compiler
+ *
+ * @param messages
+ * @return the short error message
+ * @since 2.0.2
+ */
+ public static String shortMessage( List<CompilerError> messages )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( "Compilation failure" );
+
+ if ( messages.size() == 1 )
+ {
+ sb.append( LS );
+
+ CompilerError compilerError = messages.get( 0 );
+
+ sb.append( compilerError ).append( LS );
+ }
+
+ return sb.toString();
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/CompilationFailureException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/CompilationFailureException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/LightningGeneratorMojo.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/LightningGeneratorMojo.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/LightningGeneratorMojo.java (added)
+++ directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/LightningGeneratorMojo.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,437 @@
+/*
+ * 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.
+ */
+package org.apache.directmemory.lightning.maven;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.tools.SimpleJavaFileObject;
+
+import org.apache.directmemory.lightning.SerializationStrategy;
+import org.apache.directmemory.lightning.Serializer;
+import org.apache.directmemory.lightning.base.AbstractSerializerDefinition;
+import org.apache.directmemory.lightning.configuration.SerializerDefinition;
+import org.apache.directmemory.lightning.logging.LogLevel;
+import org.apache.directmemory.lightning.logging.Logger;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
+import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
+import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
+
+/**
+ * Generates sourcecode of native marshallers for Lightning {@link Serializer} by exploring all source
+ * {@link SerializerDefinition} files.
+ *
+ * @goal generate
+ * @lifecycle process-classes
+ * @phase process-classes
+ * @execute phase="process-classes"
+ * @execute goal="process-classes:generate"
+ * @requiresDependencyResolution compile
+ * @requiresProject true
+ * @threadSafe true
+ */
+public class LightningGeneratorMojo
+ extends AbstractCompilerMojo
+{
+
+ /**
+ * The current build session instance. This is used for toolchain manager API calls.
+ *
+ * @parameter default-value="${session}"
+ * @required
+ * @readonly
+ */
+ private MavenSession session;
+
+ /**
+ * The java generated-source directory.
+ *
+ * @parameter default-value= "${project.build.directory}/generated-sources/lightning"
+ */
+ private File generatedSourceDirectory;
+
+ /**
+ * The directory where compiled classes resist.
+ *
+ * @parameter default-value="${project.build.directory}/classes"
+ */
+ private File targetBuildDirectory;
+
+ /**
+ * Project classpath.
+ *
+ * @parameter default-value="${project.compileClasspathElements}"
+ * @required
+ * @readonly
+ */
+ private List<String> classpathElements;
+
+ /**
+ * The generator strategy.
+ *
+ * @parameter default-value="speed"
+ */
+ private String strategy;
+
+ @Override
+ public void execute()
+ throws MojoExecutionException, CompilationFailureException
+ {
+ if ( encoding == null )
+ {
+ encoding = "UTF-8";
+ }
+
+ SerializationStrategy serializationStrategy =
+ "size".equalsIgnoreCase( strategy ) ? SerializationStrategy.SizeOptimized
+ : SerializationStrategy.SpeedOptimized;
+
+ MavenLoggerAdapter logger = new MavenLoggerAdapter( LightningGeneratorMojo.class.getCanonicalName() );
+ getLog().info( "Searching in path " + targetBuildDirectory.getAbsolutePath() );
+ List<File> files =
+ SupportUtil.recursiveGetAllJavaSources( targetBuildDirectory, new ArrayList<File>(), fileFilter );
+
+ List<URL> urlClasspathElements = new ArrayList<URL>();
+ if ( getClasspathElements() != null )
+ {
+ for ( String classpathElement : getClasspathElements() )
+ {
+ try
+ {
+ URL url = new File( classpathElement ).toURI().toURL();
+ urlClasspathElements.add( url );
+ }
+ catch ( Exception e )
+ {
+ // Intentionally left blank
+ }
+ }
+ }
+ ClassLoader classLoader =
+ new URLClassLoader( urlClasspathElements.toArray( new URL[urlClasspathElements.size()] ),
+ getClass().getClassLoader() );
+
+ for ( File file : files )
+ {
+ try
+ {
+ String className = file.getAbsolutePath().replace( targetBuildDirectory.getAbsolutePath(), "" );
+ if ( className.startsWith( "/" ) || className.startsWith( "\\" ) )
+ {
+ className = className.substring( 1 );
+ }
+
+ className = className.replace( ".class", "" ).replace( "/", "." ).replace( "\\", "." );
+
+ getLog().debug( "Trying class " + className );
+ Class<?> clazz = classLoader.loadClass( className );
+ if ( AbstractSerializerDefinition.class.isAssignableFrom( clazz ) )
+ {
+ getLog().debug( "Found SerializerDefinition in class " + className );
+
+ AbstractSerializerDefinition definition = (AbstractSerializerDefinition) clazz.newInstance();
+
+ SerializerDefinitionAnalyser analyser = new SerializerDefinitionAnalyser( logger );
+ analyser.analyse( definition );
+ analyser.build( generatedSourceDirectory, serializationStrategy, encoding );
+ }
+ }
+ catch ( Exception e )
+ {
+ logger.error( "Could not generate Lightning source for file " + file.getName(), e );
+ }
+ }
+
+ super.execute();
+
+ // session.getCurrentProject().addCompileSourceRoot(generatedSourceDirectory.getAbsolutePath());
+ }
+
+ @Override
+ protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
+ {
+ return new StaleSourceScanner( staleMillis );
+ }
+
+ @Override
+ protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
+ {
+ return new SimpleSourceInclusionScanner( Collections.singleton( "**/*.java" ), Collections.EMPTY_SET );
+ }
+
+ @Override
+ protected List<String> getClasspathElements()
+ {
+ return classpathElements;
+ }
+
+ @Override
+ protected List<String> getCompileSourceRoots()
+ {
+ return Collections.singletonList( generatedSourceDirectory.getAbsolutePath() );
+ }
+
+ @Override
+ protected File getOutputDirectory()
+ {
+ return targetBuildDirectory;
+ }
+
+ @Override
+ protected String getSource()
+ {
+ return source;
+ }
+
+ @Override
+ protected String getTarget()
+ {
+ return target;
+ }
+
+ @Override
+ protected String getCompilerArgument()
+ {
+ return compilerArgument;
+ }
+
+ @Override
+ protected Map<String, String> getCompilerArguments()
+ {
+ return compilerArguments;
+ }
+
+ @Override
+ protected File getGeneratedSourcesDirectory()
+ {
+ return generatedSourceDirectory;
+ }
+
+ private final FileFilter fileFilter = new FileFilter()
+ {
+
+ @Override
+ public boolean accept( File file )
+ {
+ return file.isDirectory() || file.getName().endsWith( ".class" );
+ }
+ };
+
+ private class FileObject
+ extends SimpleJavaFileObject
+ {
+
+ private final Charset charset;
+
+ private final File file;
+
+ private FileObject( File file, Charset charset )
+ {
+ super( file.toURI(), Kind.SOURCE );
+ this.charset = charset;
+ this.file = file;
+ }
+
+ @Override
+ public CharSequence getCharContent( boolean ignoreEncodingErrors )
+ throws IOException
+ {
+ return SupportUtil.readAllText( file, charset );
+ }
+ }
+
+ private class MavenLoggerAdapter
+ implements Logger
+ {
+
+ private final String name;
+
+ private MavenLoggerAdapter( String name )
+ {
+ this.name = name;
+ }
+
+ @Override
+ public Logger getChildLogger( Class<?> clazz )
+ {
+ return getChildLogger( clazz.getCanonicalName() );
+ }
+
+ @Override
+ public Logger getChildLogger( String name )
+ {
+ return new MavenLoggerAdapter( name );
+ }
+
+ @Override
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public boolean isLogLevelEnabled( LogLevel logLevel )
+ {
+ if ( logLevel == LogLevel.Debug )
+ {
+ return getLog().isDebugEnabled();
+ }
+
+ if ( logLevel == LogLevel.Error )
+ {
+ return getLog().isErrorEnabled();
+ }
+
+ if ( logLevel == LogLevel.Fatal )
+ {
+ return getLog().isErrorEnabled();
+ }
+
+ if ( logLevel == LogLevel.Trace )
+ {
+ return getLog().isDebugEnabled();
+ }
+
+ if ( logLevel == LogLevel.Warn )
+ {
+ return getLog().isWarnEnabled();
+ }
+
+ return getLog().isInfoEnabled();
+ }
+
+ @Override
+ public boolean isTraceEnabled()
+ {
+ return isLogLevelEnabled( LogLevel.Trace );
+ }
+
+ @Override
+ public boolean isDebugEnabled()
+ {
+ return isLogLevelEnabled( LogLevel.Debug );
+ }
+
+ @Override
+ public boolean isInfoEnabled()
+ {
+ return isLogLevelEnabled( LogLevel.Info );
+ }
+
+ @Override
+ public boolean isWarnEnabled()
+ {
+ return isLogLevelEnabled( LogLevel.Warn );
+ }
+
+ @Override
+ public boolean isErrorEnabled()
+ {
+ return isLogLevelEnabled( LogLevel.Error );
+ }
+
+ @Override
+ public boolean isFatalEnabled()
+ {
+ return isLogLevelEnabled( LogLevel.Fatal );
+ }
+
+ @Override
+ public void trace( String message )
+ {
+ trace( message, null );
+ }
+
+ @Override
+ public void trace( String message, Throwable throwable )
+ {
+ debug( message, throwable );
+ }
+
+ @Override
+ public void debug( String message )
+ {
+ debug( message, null );
+ }
+
+ @Override
+ public void debug( String message, Throwable throwable )
+ {
+ getLog().debug( message, throwable );
+ }
+
+ @Override
+ public void info( String message )
+ {
+ info( message, null );
+ }
+
+ @Override
+ public void info( String message, Throwable throwable )
+ {
+ getLog().info( message, throwable );
+ }
+
+ @Override
+ public void warn( String message )
+ {
+ warn( message, null );
+ }
+
+ @Override
+ public void warn( String message, Throwable throwable )
+ {
+ getLog().warn( message, throwable );
+ }
+
+ @Override
+ public void error( String message )
+ {
+ error( message, null );
+ }
+
+ @Override
+ public void error( String message, Throwable throwable )
+ {
+ getLog().error( message, throwable );
+ }
+
+ @Override
+ public void fatal( String message )
+ {
+ fatal( message, null );
+ }
+
+ @Override
+ public void fatal( String message, Throwable throwable )
+ {
+ error( message, throwable );
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/LightningGeneratorMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/LightningGeneratorMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SerializerDefinitionAnalyser.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SerializerDefinitionAnalyser.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SerializerDefinitionAnalyser.java (added)
+++ directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SerializerDefinitionAnalyser.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,226 @@
+/*
+ * 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.
+ */
+package org.apache.directmemory.lightning.maven;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import org.apache.directmemory.lightning.Marshaller;
+import org.apache.directmemory.lightning.MarshallerStrategy;
+import org.apache.directmemory.lightning.SerializationStrategy;
+import org.apache.directmemory.lightning.configuration.SerializerDefinition;
+import org.apache.directmemory.lightning.generator.DefinitionBuildingContext;
+import org.apache.directmemory.lightning.generator.DefinitionVisitor;
+import org.apache.directmemory.lightning.generator.PropertyDescriptorFactory;
+import org.apache.directmemory.lightning.internal.InternalClassDescriptor;
+import org.apache.directmemory.lightning.internal.InternalDefinitionBuildingContext;
+import org.apache.directmemory.lightning.internal.InternalMarshallerStrategy;
+import org.apache.directmemory.lightning.internal.beans.InternalPropertyDescriptorFactory;
+import org.apache.directmemory.lightning.internal.util.ClassUtil;
+import org.apache.directmemory.lightning.internal.util.TypeUtil;
+import org.apache.directmemory.lightning.logging.Logger;
+import org.apache.directmemory.lightning.metadata.Attribute;
+import org.apache.directmemory.lightning.metadata.ClassDefinition;
+import org.apache.directmemory.lightning.metadata.ClassDescriptor;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class SerializerDefinitionAnalyser
+{
+
+ private final Logger logger;
+
+ private final Map<Class<?>, InternalClassDescriptor> classDescriptors =
+ new HashMap<Class<?>, InternalClassDescriptor>();
+
+ private final List<SerializerDefinition> serializerDefinitions = new ArrayList<SerializerDefinition>();
+
+ private final Map<Class<?>, Marshaller> marshallers = new HashMap<Class<?>, Marshaller>();
+
+ private Class<? extends Annotation> attributeAnnotation = Placeholder.class;
+
+ private final DefinitionVisitor definitionVisitor = new GeneratorDefinitionVisitor();
+
+ public SerializerDefinitionAnalyser( Logger logger )
+ {
+ this.logger = logger;
+ }
+
+ public void analyse( SerializerDefinition serializerDefinition )
+ {
+ PropertyDescriptorFactory propertyDescriptorFactory = new InternalPropertyDescriptorFactory( logger );
+ MarshallerStrategy marshallerStrategy = new InternalMarshallerStrategy();
+ DefinitionBuildingContext definitionBuildingContext =
+ new InternalDefinitionBuildingContext( marshallerStrategy, propertyDescriptorFactory );
+
+ serializerDefinition.configure( definitionBuildingContext, null );
+ serializerDefinition.acceptVisitor( definitionVisitor );
+ }
+
+ public List<File> build( File outputFolder, SerializationStrategy serializationStrategy, String encoding )
+ {
+ Charset charset = Charset.forName( encoding );
+
+ List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>();
+ for ( InternalClassDescriptor classDescriptor : classDescriptors.values() )
+ {
+ classDefinitions.add( classDescriptor.build( ClassUtil.CLASS_DESCRIPTORS ).getClassDefinition() );
+ }
+
+ List<File> files = new ArrayList<File>();
+ for ( ClassDescriptor classDescriptor : classDescriptors.values() )
+ {
+ if ( classDescriptor instanceof InternalClassDescriptor && classDescriptor.getMarshaller() == null )
+ {
+ try
+ {
+ SourceMarshallerGenerator generator = new SourceMarshallerGenerator( charset, logger );
+ File sourceFile =
+ generator.generateMarshaller( classDescriptor.getType(),
+ classDescriptor.getPropertyDescriptors(), serializationStrategy,
+ outputFolder );
+
+ files.add( sourceFile );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return files;
+ }
+
+ public List<SerializerDefinition> getVisitedSerializerDefinitions()
+ {
+ return serializerDefinitions;
+ }
+
+ private InternalClassDescriptor findClassDescriptor( Class<?> type )
+ {
+ InternalClassDescriptor classDescriptor = classDescriptors.get( type );
+ if ( classDescriptor == null )
+ {
+ classDescriptor = new InternalClassDescriptor( type, logger );
+ classDescriptors.put( type, classDescriptor );
+ }
+
+ return classDescriptor;
+ }
+
+ private class GeneratorDefinitionVisitor
+ implements DefinitionVisitor
+ {
+
+ private final Stack<Class<? extends Annotation>> attributeAnnotation = new Stack<Class<? extends Annotation>>();
+
+ @Override
+ public void visitSerializerDefinition( SerializerDefinition serializerDefinition )
+ {
+ // If at top level definition just add the base annotation
+ if ( attributeAnnotation.size() == 0 )
+ {
+ if ( SerializerDefinitionAnalyser.this.attributeAnnotation == null )
+ {
+ attributeAnnotation.push( Attribute.class );
+ }
+ else
+ {
+ attributeAnnotation.push( SerializerDefinitionAnalyser.this.attributeAnnotation );
+ }
+ }
+ else
+ {
+ Class<? extends Annotation> annotation = attributeAnnotation.peek();
+ attributeAnnotation.push( annotation );
+ }
+
+ // Save visited SerializerDefinition
+ serializerDefinitions.add( serializerDefinition );
+ }
+
+ @Override
+ public void visitAttributeAnnotation( Class<? extends Annotation> attributeAnnotation )
+ {
+ // Remove last element and replace it with the real annotation to
+ // use right from that moment
+ this.attributeAnnotation.pop();
+ this.attributeAnnotation.push( attributeAnnotation );
+ }
+
+ @Override
+ public void visitClassDefine( Type type, Marshaller marshaller )
+ {
+ Class<?> rawType = TypeUtil.getBaseType( type );
+ InternalClassDescriptor classDescriptor = findClassDescriptor( rawType );
+ classDescriptor.setMarshaller( marshaller );
+
+ marshallers.put( rawType, marshaller );
+ }
+
+ @Override
+ public void visitAnnotatedAttribute( PropertyDescriptor propertyDescriptor, Marshaller marshaller )
+ {
+ InternalClassDescriptor classDescriptor = findClassDescriptor( propertyDescriptor.getDefinedClass() );
+
+ if ( logger.isTraceEnabled() )
+ {
+ logger.trace( "Found property " + propertyDescriptor.getName() + " ("
+ + propertyDescriptor.getInternalSignature() + ") on type "
+ + propertyDescriptor.getDefinedClass().getCanonicalName() );
+ }
+
+ classDescriptor.push( propertyDescriptor );
+ }
+
+ @Override
+ public void visitPropertyDescriptor( PropertyDescriptor propertyDescriptor, Marshaller marshaller )
+ {
+ InternalClassDescriptor classDescriptor = findClassDescriptor( propertyDescriptor.getDefinedClass() );
+
+ if ( logger.isTraceEnabled() )
+ {
+ logger.trace( "Found property " + propertyDescriptor.getName() + " ("
+ + propertyDescriptor.getInternalSignature() + ") on type "
+ + propertyDescriptor.getDefinedClass().getCanonicalName() );
+ }
+
+ classDescriptor.push( propertyDescriptor );
+ }
+
+ @Override
+ public void visitFinalizeSerializerDefinition( SerializerDefinition serializerDefinition )
+ {
+ // Clean this level up
+ this.attributeAnnotation.pop();
+ }
+ }
+
+ public static @interface Placeholder
+ {
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SerializerDefinitionAnalyser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SerializerDefinitionAnalyser.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SourceMarshallerGenerator.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SourceMarshallerGenerator.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SourceMarshallerGenerator.java (added)
+++ directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SourceMarshallerGenerator.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,210 @@
+/*
+ * 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.
+ */
+package org.apache.directmemory.lightning.maven;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.directmemory.lightning.SerializationStrategy;
+import org.apache.directmemory.lightning.logging.Logger;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+
+public class SourceMarshallerGenerator
+{
+
+ private final VelocityEngine engine;
+
+ private final Template marshallerTemplate;
+
+ private final Charset charset;
+
+ private final Logger logger;
+
+ public SourceMarshallerGenerator( Charset charset, Logger logger )
+ throws IOException
+ {
+ this.charset = charset;
+ this.logger = logger;
+
+ Properties properties = new Properties();
+ InputStream stream = getClass().getClassLoader().getResourceAsStream( "velocity.properties" );
+ properties.load( stream );
+ engine = new VelocityEngine( properties );
+
+ engine.init();
+ marshallerTemplate = engine.getTemplate( "marshaller.vm", "UTF-8" );
+ }
+
+ public File generateMarshaller( Class<?> type, List<PropertyDescriptor> propertyDescriptors,
+ SerializationStrategy serializationStrategy, File outputFolder )
+ throws IOException
+ {
+
+ // Copy properties and sort them by name
+ List<PropertyDescriptor> propertyDescriptorsCopy = new ArrayList<PropertyDescriptor>( propertyDescriptors );
+ Collections.sort( propertyDescriptorsCopy );
+
+ String packageName = type.getPackage() != null ? type.getPackage().getName() : "lightning";
+ String className = type.getName().replace( packageName + ".", "" ) + "LightningGeneratedMarshaller";
+
+ File packageFolder = new File( outputFolder, packageName.replace( ".", "/" ) );
+ if ( !packageFolder.exists() )
+ {
+ packageFolder.mkdirs();
+ }
+
+ File outputFile = new File( packageFolder, className + ".java" );
+
+ logger.info( "Generating source :" + outputFile.getAbsolutePath() );
+
+ FileOutputStream stream = new FileOutputStream( outputFile );
+ OutputStreamWriter writer = new OutputStreamWriter( stream, charset );
+
+ VelocityContext context = new VelocityContext();
+
+ context.put( "support", new Support() );
+ context.put( "packageName", packageName );
+ context.put( "className", className );
+ context.put( "properties", propertyDescriptorsCopy );
+ context.put( "strategy", serializationStrategy.name() );
+
+ marshallerTemplate.merge( context, writer );
+
+ writer.flush();
+ writer.close();
+
+ return outputFile;
+ }
+
+ public static class Support
+ {
+
+ public String toFinalFieldName( String prefix, PropertyDescriptor propertyDescriptor )
+ {
+ return new StringBuilder( prefix.toUpperCase() ).append( "_" ).append( propertyDescriptor.getPropertyName().toUpperCase() ).append( "_LIGHTNING" ).toString();
+ }
+
+ public String generateWriter( PropertyDescriptor propertyDescriptor, String instanceName )
+ {
+ StringBuilder sb =
+ new StringBuilder( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor.write" );
+ Class<?> type = propertyDescriptor.getType();
+ if ( type == boolean.class )
+ {
+ sb.append( "Boolean(" ).append( instanceName ).append( ", ((Boolean) " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ").booleanValue())" );
+ }
+ else if ( type == byte.class )
+ {
+ sb.append( "Byte(" ).append( instanceName ).append( ", ((Byte) " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ").byteValue())" );
+ }
+ else if ( type == char.class )
+ {
+ sb.append( "Char(" ).append( instanceName ).append( ", ((Character) " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ").charValue())" );
+ }
+ else if ( type == short.class )
+ {
+ sb.append( "Short(" ).append( instanceName ).append( ", ((Short) " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ").shortValue())" );
+ }
+ else if ( type == int.class )
+ {
+ sb.append( "Int(" ).append( instanceName ).append( ", ((Integer) " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ").intValue())" );
+ }
+ else if ( type == long.class )
+ {
+ sb.append( "Long(" ).append( instanceName ).append( ", ((Long) " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ").longValue())" );
+ }
+ else if ( type == float.class )
+ {
+ sb.append( "Float(" ).append( instanceName ).append( ", ((Float) " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ").floatValue())" );
+ }
+ else if ( type == double.class )
+ {
+ sb.append( "Double(" ).append( instanceName ).append( ", ((Double) " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ").doubleValue())" );
+ }
+ else
+ {
+ sb.append( "Object(" ).append( instanceName ).append( ", " ).append( propertyDescriptor.getPropertyName() ).append( "Value" ).append( ")" );
+ }
+
+ return sb.append( ";" ).toString();
+ }
+
+ public String generateReader( PropertyDescriptor propertyDescriptor )
+ {
+ StringBuilder sb = new StringBuilder();
+ Class<?> type = propertyDescriptor.getType();
+ if ( type == boolean.class )
+ {
+ sb.append( "Boolean.valueOf(" ).append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readBoolean(" );
+ }
+ else if ( type == byte.class )
+ {
+ sb.append( "Byte.valueOf(" ).append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readByte(" );
+ }
+ else if ( type == char.class )
+ {
+ sb.append( "Character.valueOf(" ).append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readChar(" );
+ }
+ else if ( type == short.class )
+ {
+ sb.append( "Short.valueOf(" ).append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readShort(" );
+ }
+ else if ( type == int.class )
+ {
+ sb.append( "Integer.valueOf(" ).append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readInt(" );
+ }
+ else if ( type == long.class )
+ {
+ sb.append( "Long.valueOf(" ).append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readLong(" );
+ }
+ else if ( type == float.class )
+ {
+ sb.append( "Float.valueOf(" ).append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readFloat(" );
+ }
+ else if ( type == double.class )
+ {
+ sb.append( "Double.valueOf(" ).append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readDouble(" );
+ }
+ else
+ {
+ sb.append( propertyDescriptor.getPropertyName() ).append( "PropertyAccessor" ).append( ".readObject(" );
+ }
+
+ sb.append( "value)" );
+
+ if ( type.isPrimitive() )
+ {
+ sb.append( ")" );
+ }
+
+ return sb.toString();
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SourceMarshallerGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SourceMarshallerGenerator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SupportUtil.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SupportUtil.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SupportUtil.java (added)
+++ directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SupportUtil.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+package org.apache.directmemory.lightning.maven;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+
+public final class SupportUtil
+{
+
+ private SupportUtil()
+ {
+ }
+
+ public static List<File> recursiveGetAllJavaSources( File file, ArrayList<File> list, FileFilter fileFilter )
+ {
+ if ( file.isDirectory() )
+ {
+ for ( File f : file.listFiles( fileFilter ) )
+ {
+ recursiveGetAllJavaSources( f, list, fileFilter );
+ }
+ }
+ else
+ {
+ list.add( file );
+ }
+ return list;
+ }
+
+ public static String readAllText( File file, Charset charset )
+ {
+ try
+ {
+ StringBuilder sb = new StringBuilder();
+ LineNumberReader reader = new LineNumberReader( new FileReader( file ) );
+ String line = null;
+ while ( ( line = reader.readLine() ) != null )
+ {
+ sb.append( line );
+ }
+ return sb.toString();
+ }
+ catch ( IOException e )
+ {
+ return null;
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SupportUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-maven-plugin/src/main/java/org/apache/directmemory/lightning/maven/SupportUtil.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision