Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Code generation support for application running in a fat JAR #43

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
226 changes: 105 additions & 121 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,126 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project 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" xmlns="http://maven.apache.org/POM/4.0.0">

<modelVersion>4.0.0</modelVersion>
<groupId>com.mysema.codegen</groupId>
<artifactId>codegen</artifactId>
<version>0.6.9.BUILD-SNAPSHOT</version>
<name>Codegen</name>
<description>Code generation and compilation for Java</description>

<parent>
<groupId>com.mysema.home</groupId>
<artifactId>mysema-source</artifactId>
<version>0.3.1</version>
</parent>

<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mysema.codegen</groupId>
<artifactId>codegen</artifactId>
<version>0.6.9.BUILD-SNAPSHOT</version>
<name>Codegen</name>
<description>Code generation and compilation for Java</description>

<inceptionYear>2010</inceptionYear>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<scm>
<connection>scm:git:[email protected]:querydsl/codegen.git</connection>
<url>[email protected]:querydsl/codegen.git</url>
</scm>

<properties>
<commons.collections.version>4.01</commons.collections.version>
<commons.lang.version>3.0.1</commons.lang.version>
<guava.version>11.0.2</guava.version>
<ecj.version>4.3.1</ecj.version>
</properties>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>

<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>${ecj.version}</version>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.CR3</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<useDefaultManifestFile>true</useDefaultManifestFile>
</configuration>
</plugin>
<plugin>
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
<version>1.0.0.RELEASE</version>
<executions>
<execution>
<id>bundlor</id>
<goals>
<goal>bundlor</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnWarnings>true</failOnWarnings>
</configuration>
</plugin>
</plugins>
</build>

<!--
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
-->

<pluginRepositories>
<pluginRepository>
<id>com.springsource.repository.bundles.release</id>
<url>http://repository.springsource.com/maven/bundles/release</url>
</pluginRepository>
</pluginRepositories>
<parent>
<groupId>com.mysema.home</groupId>
<artifactId>mysema-source</artifactId>
<version>0.3.1</version>
</parent>

<packaging>jar</packaging>

<inceptionYear>2010</inceptionYear>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<scm>
<connection>scm:git:[email protected]:querydsl/codegen.git</connection>
<url>[email protected]:querydsl/codegen.git</url>
</scm>

<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<commons.collections.version>4.01</commons.collections.version>
<commons.lang.version>3.0.1</commons.lang.version>
<guava.version>11.0.2</guava.version>
<ecj.version>4.3.1</ecj.version>
</properties>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>

<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>${ecj.version}</version>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
<version>1.0.0.RELEASE</version>
<executions>
<execution>
<id>bundlor</id>
<goals>
<goal>bundlor</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnWarnings>true</failOnWarnings>
</configuration>
</plugin>
</plugins>
</build>

<pluginRepositories>
<pluginRepository>
<id>com.springsource.repository.bundles.release</id>
<url>http://repository.springsource.com/maven/bundles/release</url>
</pluginRepository>
</pluginRepositories>

</project>
128 changes: 128 additions & 0 deletions src/main/java/com/mysema/codegen/CompiledJavaFileObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright 2018, The Querydsl Team (http://www.querydsl.com/team)
*
* 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 com.mysema.codegen;

import java.net.URI;
import java.io.*;
import javax.tools.JavaFileObject;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.Modifier;

/**
* CompiledJavaFileObject defines a Java class file object that can be in a folder or in a JAR.
*
* NOTE: This is a derivative work from an article of atamur.
* Original article can be found here: http://atamur.blogspot.com/2009/10/using-built-in-javacompiler-with-custom.html
*
* @author matteo-gallo-bb
*/
class CompiledJavaFileObject implements JavaFileObject {

private final String binaryName;

private final URI uri;

private final String name;

public CompiledJavaFileObject(String binaryName, URI uri) {
this.uri = uri;
this.binaryName = binaryName;
// for FS based URI the path is not null, for JAR URI the scheme specific part is not null
name = uri.getPath() == null ? uri.getSchemeSpecificPart() : uri.getPath();
}

@Override
public URI toUri() {
return uri;
}

@Override
public InputStream openInputStream() throws IOException {
// easy way to handle any URI!
return uri.toURL().openStream();
}

@Override
public OutputStream openOutputStream() {
throw new UnsupportedOperationException();
}

@Override
public String getName() {
return name;
}

@Override
public Reader openReader(boolean ignoreEncodingErrors) {
throw new UnsupportedOperationException();
}

@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
throw new UnsupportedOperationException();
}

@Override
public Writer openWriter() {
throw new UnsupportedOperationException();
}

@Override
public long getLastModified() {
return 0;
}

@Override
public boolean delete() {
throw new UnsupportedOperationException();
}

@Override
public Kind getKind() {
return Kind.CLASS;
}

@Override
// copied from SimpleJavaFileObject
public boolean isNameCompatible(String simpleName, Kind kind) {
String baseName = simpleName + kind.extension;
return kind.equals(getKind())
&& (baseName.equals(getName())
|| getName().endsWith("/" + baseName));
}

@Override
public NestingKind getNestingKind() {
throw new UnsupportedOperationException();
}

@Override
public Modifier getAccessLevel() {
throw new UnsupportedOperationException();
}

public String binaryName() {
return binaryName;
}


@Override
public String toString() {
return "CustomJavaFileObject{" +
"uri=" + uri +
'}';
}
}
Loading