Skip to content

Commit

Permalink
Class Index.
Browse files Browse the repository at this point in the history
Annotation processor which indexes classes at compile-time.
  • Loading branch information
sentinelt committed Dec 12, 2011
0 parents commit 550dcfc
Show file tree
Hide file tree
Showing 33 changed files with 1,605 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
target/
bin/
.settings/
.direct_classpath
.classpath
.project
.config/
57 changes: 57 additions & 0 deletions classindex-transformer/pom.xml
@@ -0,0 +1,57 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.atteo</groupId>
<artifactId>evo-framework</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>evo-classindex-transformer</artifactId>
<name>Evo Class Index Transformer</name>
<properties>
<maven-shade-plugin.version>1.4</maven-shade-plugin.version>
<exec-maven-plugin.version>1.2.1</exec-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<type>maven-plugin</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
<configuration>
<localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<settingsFile>src/it/settings.xml</settingsFile>
<noLog>true</noLog>
</configuration>
</execution>
</executions>
</plugin>
<!-- Put here just to cache plugin artifact for integration tests -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
</plugin>
<!-- Put here just to cache plugin artifact for integration tests -->
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>

36 changes: 36 additions & 0 deletions classindex-transformer/src/it/settings.xml
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<settings>
<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>

16 changes: 16 additions & 0 deletions classindex-transformer/src/it/simple/first/pom.xml
@@ -0,0 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.atteo</groupId>
<artifactId>evo-classindex-transformer-test-first</artifactId>
<version>@project.version@</version>
<name>Evo Class Index Transformer Test First</name>
<dependencies>
<dependency>
<groupId>org.atteo</groupId>
<artifactId>evo-classindex</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

@@ -0,0 +1,19 @@
/*
* 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.
*/
package org.atteo.evo.classindex;

@IndexAnnotated
public @interface Component {

}
@@ -0,0 +1,18 @@
/*
* 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.
*/
package org.atteo.evo.classindex;

@Component
public class FirstComponent {
}
@@ -0,0 +1,18 @@
/*
* 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.
*/
package org.atteo.evo.classindex;

public class FirstService implements Service {

}
@@ -0,0 +1,18 @@
/*
* 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.
*/
package org.atteo.evo.classindex;

@IndexSubclasses
public interface Service {
}
@@ -0,0 +1,15 @@
/*
* 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.
*/
@IndexSubclasses
package org.atteo.evo.classindex;
14 changes: 14 additions & 0 deletions classindex-transformer/src/it/simple/pom.xml
@@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.atteo</groupId>
<artifactId>evo-classindex-transformer-test</artifactId>
<version>@project.version@</version>
<packaging>pom</packaging>
<name>Evo Class Index Transformer Test</name>
<modules>
<module>first</module>
<module>second</module>
</modules>
</project>

66 changes: 66 additions & 0 deletions classindex-transformer/src/it/simple/second/pom.xml
@@ -0,0 +1,66 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.atteo</groupId>
<artifactId>evo-classindex-transformer-test-second</artifactId>
<version>@project.version@</version>
<name>Evo Class Index Transformer Test Second</name>
<dependencies>
<dependency>
<groupId>org.atteo</groupId>
<artifactId>evo-classindex-transformer-test-first</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>@maven-shade-plugin.version@</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.atteo.evo.classindex.ClassIndexTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.atteo</groupId>
<artifactId>evo-classindex-transformer</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@exec-maven-plugin.version@</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<argument>${project.build.directory}/${project.build.finalName}.jar</argument>
<argument>org.atteo.evo.classindex.ClassIndexTest</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@@ -0,0 +1,37 @@
/*
* 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.
*/
package org.atteo.evo.classindex;

import java.util.ServiceLoader;
import com.google.common.collect.Iterables;

public class ClassIndexTest {
public static void main(String[] args) {
Iterable<Class<? extends Service>> services = ClassIndex.getSubclasses(Service.class);
assertEquals(2, Iterables.size(services));
Iterable<Class<?>> annotated = ClassIndex.getAnnotated(Component.class);
assertEquals(2, Iterables.size(annotated));
Iterable<Class<?>> packageSubclasses = ClassIndex.getPackageClasses(
ClassIndexTest.class.getPackage().getName());
assertEquals(7, Iterables.size(packageSubclasses));
ServiceLoader<Service> loader = ServiceLoader.load(Service.class);
assertEquals(2, Iterables.size(loader));
}

private static void assertEquals(int expected, int actual) {
if (expected != actual) {
throw new RuntimeException("Test has failed. Expected: " + expected + ", actual: " + actual);
}
}
}
@@ -0,0 +1,18 @@
/*
* 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.
*/
package org.atteo.evo.classindex;

@Component
public class SecondComponent {
}
@@ -0,0 +1,17 @@
/*
* 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.
*/
package org.atteo.evo.classindex;

public class SecondService implements Service {
}

0 comments on commit 550dcfc

Please sign in to comment.