Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@
<enforceStandards>false</enforceStandards>
<enforceBestPractices>false</enforceBestPractices>
<plugin.jacoco.skip>false</plugin.jacoco.skip>
<version.groovy-templates>5.1.0</version.groovy-templates>
<version.plugin.compiler>3.15.0</version.plugin.compiler>
<version.plugin.jacoco>0.8.15</version.plugin.jacoco>
</properties>

<modules>
<module>rwx</module>
<module>rwx-processor</module>
<module>rwx-test</module>
</modules>

Expand All @@ -62,9 +66,14 @@
<version>2.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<groupId>org.commonjava.rwx</groupId>
<artifactId>rwx-processor</artifactId>
<version>2.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-templates</artifactId>
<version>3.0.17</version>
<version>${version.groovy-templates}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -105,19 +114,19 @@
<artifactId>hamcrest-core</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${version.plugin.javadoc}</version>
<configuration>
<detectOfflineLinks>false</detectOfflineLinks>
<additionalOptions>-Xdoclint:none</additionalOptions>
<additionalJOption>-Xdoclint:none</additionalJOption>
<doclint>none</doclint>
<source>8</source>
<source>${javaVersion}</source>
<links />
</configuration>
</plugin>
Expand Down
43 changes: 43 additions & 0 deletions rwx-processor/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava)

Licensed 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>

<parent>
<groupId>org.commonjava.rwx</groupId>
<artifactId>rwx-parent</artifactId>
<version>2.6-SNAPSHOT</version>
</parent>

<artifactId>rwx-processor</artifactId>

<name>RWX::Processor</name>

<dependencies>
<dependency>
<groupId>org.commonjava.rwx</groupId>
<artifactId>rwx</artifactId>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-templates</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava)
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.commonjava.rwx.core;
package org.commonjava.rwx.processor;

import groovy.lang.Writable;
import groovy.text.GStringTemplateEngine;
Expand All @@ -26,7 +26,6 @@
import org.commonjava.rwx.anno.Request;
import org.commonjava.rwx.anno.Response;
import org.commonjava.rwx.anno.StructPart;
import org.commonjava.rwx.util.ProcessorUtils;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
Expand All @@ -41,24 +40,26 @@
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import java.io.IOException;
import java.net.URL;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;

import static org.commonjava.rwx.util.ProcessorUtils.GENERATED;
import static org.commonjava.rwx.util.ProcessorUtils.getElementClassByType;
import static org.commonjava.rwx.util.ProcessorUtils.getList;
import static org.commonjava.rwx.util.ProcessorUtils.getMethodName;
import static org.commonjava.rwx.util.ProcessorUtils.getPackageAndClassName;
import static org.commonjava.rwx.util.ProcessorUtils.getRegistryClassName;
import static org.commonjava.rwx.util.ProcessorUtils.union;
import static org.commonjava.rwx.processor.ProcessorUtils.GENERATED;
import static org.commonjava.rwx.processor.ProcessorUtils.getElementClassByType;
import static org.commonjava.rwx.processor.ProcessorUtils.getList;
import static org.commonjava.rwx.processor.ProcessorUtils.getMethodName;
import static org.commonjava.rwx.processor.ProcessorUtils.getPackageAndClassName;
import static org.commonjava.rwx.processor.ProcessorUtils.getRegistryClassName;
import static org.commonjava.rwx.processor.ProcessorUtils.union;

/**
* Created by ruhan on 7/24/17.
Expand Down Expand Up @@ -128,8 +129,11 @@ private void writeRegistryFile( Set<? extends Element> classes, RoundEnvironment
List<String> imports = new ArrayList<>();
List<String> simpleClassNames = new ArrayList<>();

List<Element> sortedClasses = new ArrayList<>( classes );
sortedClasses.sort( Comparator.comparing( e -> ( (TypeElement) e ).getQualifiedName().toString() ) );

Set<String> packageNames = new HashSet<>();
for ( Element elem : classes )
for ( Element elem : sortedClasses )
{
String qName = ( (TypeElement) elem ).getQualifiedName().toString();
imports.add( qName );
Expand Down Expand Up @@ -437,19 +441,15 @@ else if ( sPart != null || aPart != null )

private Template getTemplate( String templateName )
{
Template template;
try
{
final FileObject resource = processingEnv.getFiler()
.getResource( StandardLocation.CLASS_PATH, TEMPLATE_PKG,
templateName );
template = engine.createTemplate( resource.toUri().toURL() );
final URL resource = AnnoProcessor.class.getResource( "/" + TEMPLATE_PKG + "/" + templateName );
return engine.createTemplate( Objects.requireNonNull( resource ) );
}
catch ( Exception e )
{
throw new IllegalStateException( "Cannot load template: " + TEMPLATE_PKG + "/" + templateName, e );
}
return template;
}

private void generateOutput( Template template, Map<String, Object> templateParams, String className )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava)
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.commonjava.rwx.util;

import org.apache.commons.lang3.StringUtils;
package org.commonjava.rwx.processor;

import javax.lang.model.element.Element;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -43,9 +42,10 @@ private static void debug( String message )

public static final String GENERATED = "generated";

@SafeVarargs
public static <E> Set<? extends E> union( Set<? extends E>... sets )
{
Set<E> es = new HashSet<>();
Set<E> es = new LinkedHashSet<>();
for ( Set<? extends E> s : sets )
{
es.addAll( s );
Expand Down Expand Up @@ -142,7 +142,7 @@ public static String getRegistryClassName( Set<String> packageNames )
}

commonPkgName = sb.toString();
if ( StringUtils.isBlank( commonPkgName ) )
if ( commonPkgName.trim().isEmpty() )
{
return "generated._Registry"; // default
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava)
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.commonjava.rwx.core.util;
package org.commonjava.rwx.processor;

import static org.commonjava.rwx.util.ProcessorUtils.getElementClassByType;
import static org.commonjava.rwx.util.ProcessorUtils.getRegistryClassName;
import static org.commonjava.rwx.processor.ProcessorUtils.getElementClassByType;
import static org.commonjava.rwx.processor.ProcessorUtils.getRegistryClassName;
import org.junit.Test;

import java.util.Collections;
Expand Down
8 changes: 7 additions & 1 deletion rwx-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@
<generatedSourcesDirectory>${project.build.directory}/generated-sources</generatedSourcesDirectory>
<annotationProcessors>
<annotationProcessor>
org.commonjava.rwx.core.AnnoProcessor
org.commonjava.rwx.processor.AnnoProcessor
</annotationProcessor>
</annotationProcessors>
<annotationProcessorPaths>
<path>
<groupId>org.commonjava.rwx</groupId>
<artifactId>rwx-processor</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
Expand Down
4 changes: 0 additions & 4 deletions rwx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-templates</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Loading