Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how the default class translation files path is constructed #106

Closed
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
48 changes: 48 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<version.org.jboss.logmanager>3.0.4.Final</version.org.jboss.logmanager>
<verion.org.jboss.forge.roaster>2.22.3.Final</verion.org.jboss.forge.roaster>
<version.org.junit>5.10.2</version.org.junit>

<!-- Eclipse compiler properties -->
<version.org.codehaus.plexus.plexus-compiler.compiler-eclipse>2.15.0</version.org.codehaus.plexus.plexus-compiler.compiler-eclipse>
<version.org.eclipse.jdt.ecj>3.37.0</version.org.eclipse.jdt.ecj>
</properties>

<licenses>
Expand Down Expand Up @@ -182,5 +186,49 @@
</plugins>
</build>
</profile>
<profile>
<id>compiler-eclipse</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<configuration>
<compilerId>eclipse</compilerId>
<source>${maven.compiler.release}</source>
<target>${maven.compiler.release}</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>${version.org.codehaus.plexus.plexus-compiler.compiler-eclipse}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-manager</artifactId>
<version>${version.org.codehaus.plexus.plexus-compiler.compiler-eclipse}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>${version.org.codehaus.plexus.plexus-compiler.compiler-eclipse}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>${version.org.eclipse.jdt.ecj}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.annotation.processing.ProcessingEnvironment;
Expand Down Expand Up @@ -146,10 +147,18 @@ private List<File> findTranslationFiles(final MessageInterface messageInterface)
if (translationFilesPath != null) {
classTranslationFilesPath = translationFilesPath + packageName.replace('.', File.separatorChar);

//By default use the class output folder
//By default, use the class output folder
} else {
FileObject fObj = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, interfaceName);
classTranslationFilesPath = fObj.toUri().getPath().replace(interfaceName, "");
// Create some random name:
String relativeName = interfaceName + UUID.randomUUID();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's weird to me is the exception is java.io.FileNotFoundException, yet using a random file name makes it work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in the original approach, it was trying to get a resource (and eclipse compiler wants resources to actually exist) while this patch is just creating a new resource (so a potential problem could be that a file with that "random" name actually exists 🙈)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry getResource() vs createResource(). I should have noticed that.

// Eclipse compiler will throw an exception on processingEnv.getFiler().getResource(..)
// when the resource is missing, while the regular javac will just return a file object that points to
// a non-existent file.
// Since we only care about the path here ... we are going to create a dummy resource file
// that that will be cleaned up right after:
FileObject fObj = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, packageName, relativeName);
classTranslationFilesPath = fObj.toUri().getPath().replace(relativeName, "");
fObj.delete();
}
final List<File> result;
File[] files = new File(classTranslationFilesPath).listFiles(new TranslationFileFilter(interfaceName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,272 +39,113 @@ public interface MethodMessageConstants {

@Message(TEST_MSG)
@Property(name = "value", intValue = Integer.MAX_VALUE)
IntTypeException intProperty();
MethodMessageConstantsIntTypeException intProperty();

@Message(TEST_MSG)
@Property(name = "value", longValue = Long.MAX_VALUE)
LongTypeException longProperty();
MethodMessageConstantsLongTypeException longProperty();

@Message(TEST_MSG)
@Property(name = "value", shortValue = Short.MAX_VALUE)
ShortTypeException shortProperty();
MethodMessageConstantsShortTypeException shortProperty();

@Message(TEST_MSG)
@Property(name = "value", doubleValue = Double.MAX_VALUE)
DoubleTypeException douleProperty();
MethodMessageConstantsDoubleTypeException douleProperty();

@Message(TEST_MSG)
@Property(name = "value", floatValue = Float.MAX_VALUE)
FloatTypeException floatProperty();
MethodMessageConstantsFloatTypeException floatProperty();

@Message(TEST_MSG)
@Property(name = "value", booleanValue = true)
BooleanTypeException booleanProperty();
MethodMessageConstantsBooleanTypeException booleanProperty();

@Message(TEST_MSG)
@Property(name = "value", charValue = testChar)
CharTypeException charProperty();
MethodMessageConstantsCharTypeException charProperty();

@Message(TEST_MSG)
@Property(name = "value", byteValue = (byte) 'x')
ByteTypeException byteProperty();
MethodMessageConstantsByteTypeException byteProperty();

@Message(TEST_MSG)
@Property(name = "value", classValue = ValueType.class)
ClassTypeException classProperty();
MethodMessageConstantsClassTypeException classProperty();

@Message(TEST_MSG)
@Property(name = "value", stringValue = stringTest)
StringTypeException stringProperty();
MethodMessageConstantsStringTypeException stringProperty();

@Message(TEST_MSG)
@Property(name = "value", stringValue = stringTest)
@Property(name = "type", classValue = String.class)
TypeException repeatableProperty();
MethodMessageConstantsTypeException repeatableProperty();

@Message(TEST_MSG)
@Properties({
@Property(name = "value", stringValue = stringTest),
@Property(name = "type", classValue = String.class)
})
TypeException multiProperty();
MethodMessageConstantsTypeException multiProperty();

// Fields

@Message(TEST_MSG)
@Field(name = "value", intValue = Integer.MAX_VALUE)
IntTypeException intField();
MethodMessageConstantsIntTypeException intField();

@Message(TEST_MSG)
@Field(name = "value", longValue = Long.MAX_VALUE)
LongTypeException longField();
MethodMessageConstantsLongTypeException longField();

@Message(TEST_MSG)
@Field(name = "value", shortValue = Short.MAX_VALUE)
ShortTypeException shortField();
MethodMessageConstantsShortTypeException shortField();

@Message(TEST_MSG)
@Field(name = "value", doubleValue = Double.MAX_VALUE)
DoubleTypeException douleField();
MethodMessageConstantsDoubleTypeException douleField();

@Message(TEST_MSG)
@Field(name = "value", floatValue = Float.MAX_VALUE)
FloatTypeException floatField();
MethodMessageConstantsFloatTypeException floatField();

@Message(TEST_MSG)
@Field(name = "value", booleanValue = true)
BooleanTypeException booleanField();
MethodMessageConstantsBooleanTypeException booleanField();

char testChar = 'c';

@Message(TEST_MSG)
@Field(name = "value", charValue = testChar)
CharTypeException charField();
MethodMessageConstantsCharTypeException charField();

@Message(TEST_MSG)
@Field(name = "value", byteValue = (byte) 'x')
ByteTypeException byteField();
MethodMessageConstantsByteTypeException byteField();

@Message(TEST_MSG)
@Field(name = "value", classValue = ValueType.class)
ClassTypeException classField();
MethodMessageConstantsClassTypeException classField();

String stringTest = "test";

@Message(TEST_MSG)
@Field(name = "value", stringValue = stringTest)
StringTypeException stringField();
MethodMessageConstantsStringTypeException stringField();

@Message(TEST_MSG)
@Field(name = "value", stringValue = stringTest)
@Field(name = "type", classValue = String.class)
TypeException repeatableField();
MethodMessageConstantsTypeException repeatableField();

@Message(TEST_MSG)
@Fields({
@Field(name = "value", stringValue = stringTest),
@Field(name = "type", classValue = String.class)
})
TypeException multiField();

@SuppressWarnings({ "InstanceVariableMayNotBeInitialized", "unused" })
class TypeException extends RuntimeException {
public Class<?> type;
public Object value;

public TypeException() {
}

public TypeException(final String msg) {
super(msg);
}

public TypeException(final Throwable t) {
super(t);
}

public TypeException(final String msg, final Throwable t) {
super(msg, t);
}

public void setValue(final Object value) {
this.value = value;
}

public void setType(final Class<?> type) {
this.type = type;
}
}

class IntTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public int value;

public IntTypeException(final String message) {
super(message);
}

public void setValue(final Integer value) {
this.value = value;
}
}

class LongTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public long value;

public LongTypeException(final String message) {
super(message);
}

public void setValue(final long value) {
this.value = value;
}
}

class ShortTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public short value;

public ShortTypeException(final String message) {
super(message);
}

public void setValue(final short value) {
this.value = value;
}
}

class FloatTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public float value;

public FloatTypeException(final String message) {
super(message);
}

public void setValue(final float value) {
this.value = value;
}
}

class DoubleTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public double value;

public DoubleTypeException(final String message) {
super(message);
}

public void setValue(final double value) {
this.value = value;
}
}

class BooleanTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public boolean value;

public BooleanTypeException(final String message) {
super(message);
}

public void setValue(final boolean value) {
this.value = value;
}
}

class ByteTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public byte value;

public ByteTypeException(final String message) {
super(message);
}

public void setValue(final byte value) {
this.value = value;
}
}

class CharTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public char value;

public CharTypeException(final String message) {
super(message);
}

public void setValue(final char value) {
this.value = value;
}
}

class ClassTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public Class<?> value;

public ClassTypeException(final String message) {
super(message);
}

public void setValue(final Class<?> value) {
this.value = value;
}
}

class StringTypeException extends RuntimeException {
@SuppressWarnings("InstanceVariableMayNotBeInitialized")
public String value;

public StringTypeException(final String message) {
super(message);
}

public void setValue(final String value) {
this.value = value;
}
}
MethodMessageConstantsTypeException multiField();

class ValueType {
}
Expand Down
Loading