diff --git a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityName.java b/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityName.java deleted file mode 100644 index db606d6d6..000000000 --- a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityName.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity(name = "NAME_BEFORE") -public class ModifiedEntityName { -} diff --git a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityNameDefault2Explicit.java b/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityNameDefault2Explicit.java deleted file mode 100644 index a9cf5cbeb..000000000 --- a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityNameDefault2Explicit.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity -public class ModifiedEntityNameDefault2Explicit { -} diff --git a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityNameExplicit2Default.java b/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityNameExplicit2Default.java deleted file mode 100644 index f4b1dc2e5..000000000 --- a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/ModifiedEntityNameExplicit2Default.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity(name = "EXPLICIT") -public class ModifiedEntityNameExplicit2Default { -} diff --git a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/RemovedEntity.java b/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/RemovedEntity.java deleted file mode 100644 index 3bd65e3d5..000000000 --- a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/RemovedEntity.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity -public class RemovedEntity { -} diff --git a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/UnchangedEntity.java b/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/UnchangedEntity.java deleted file mode 100644 index 874e82035..000000000 --- a/japicmp-testbase/japicmp-test-v1/src/main/java/japicmp/test/jpa/UnchangedEntity.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity -public class UnchangedEntity { -} diff --git a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityName.java b/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityName.java deleted file mode 100644 index 6102a5fd3..000000000 --- a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityName.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity(name = "NAME_RENAMED") -public class ModifiedEntityName { -} diff --git a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityNameDefault2Explicit.java b/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityNameDefault2Explicit.java deleted file mode 100644 index 143325075..000000000 --- a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityNameDefault2Explicit.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity(name = "EXPLICIT") -public class ModifiedEntityNameDefault2Explicit { -} diff --git a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityNameExplicit2Default.java b/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityNameExplicit2Default.java deleted file mode 100644 index 3ac034ddd..000000000 --- a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/ModifiedEntityNameExplicit2Default.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity -public class ModifiedEntityNameExplicit2Default { -} diff --git a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/NewEntity.java b/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/NewEntity.java deleted file mode 100644 index 748ec86f0..000000000 --- a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/NewEntity.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity -public class NewEntity { -} diff --git a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/UnchangedEntity.java b/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/UnchangedEntity.java deleted file mode 100644 index 874e82035..000000000 --- a/japicmp-testbase/japicmp-test-v2/src/main/java/japicmp/test/jpa/UnchangedEntity.java +++ /dev/null @@ -1,7 +0,0 @@ -package japicmp.test.jpa; - -import javax.persistence.Entity; - -@Entity -public class UnchangedEntity { -} diff --git a/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/jpa/BasicTest.java b/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/jpa/BasicTest.java deleted file mode 100644 index a16b98ebc..000000000 --- a/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/jpa/BasicTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package japicmp.test.jpa; - -import japicmp.cmp.JarArchiveComparator; -import japicmp.cmp.JarArchiveComparatorOptions; -import japicmp.model.JApiClass; -import japicmp.output.extapi.jpa.JpaAnalyzer; -import japicmp.output.extapi.jpa.model.JpaTable; -import org.junit.Test; - -import java.util.List; - -import static japicmp.test.jpa.JpaHelper.getEntityByName; -import static japicmp.test.util.Helper.getArchive; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -public class BasicTest { - - @Test - public void basicTest() { - JarArchiveComparatorOptions options = new JarArchiveComparatorOptions(); - JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(options); - List jApiClasses = jarArchiveComparator.compare(getArchive("japicmp-test-v1.jar"), getArchive("japicmp-test-v2.jar")); - JpaAnalyzer jpaAnalyzer = new JpaAnalyzer(); - List jpaEntities = jpaAnalyzer.analyze(jApiClasses); - assertThat(getEntityByName(jpaEntities, NewEntity.class.getCanonicalName()).getFullyQualifiedName(), is(NewEntity.class.getCanonicalName())); - } -} diff --git a/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/jpa/JpaHelper.java b/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/jpa/JpaHelper.java deleted file mode 100644 index de2c375bf..000000000 --- a/japicmp-testbase/japicmp-test/src/test/java/japicmp/test/jpa/JpaHelper.java +++ /dev/null @@ -1,17 +0,0 @@ -package japicmp.test.jpa; - -import japicmp.output.extapi.jpa.model.JpaTable; - -import java.util.List; - -public class JpaHelper { - - public static JpaTable getEntityByName(List entities, String name) { - for (JpaTable jpaTable : entities) { - if (jpaTable.getFullyQualifiedName().equals(name)) { - return jpaTable; - } - } - throw new IllegalStateException("Could not find entity with name '" + name + "'."); - } -} diff --git a/japicmp/src/main/java/japicmp/output/extapi/jpa/JpaAnalyzer.java b/japicmp/src/main/java/japicmp/output/extapi/jpa/JpaAnalyzer.java deleted file mode 100644 index d7bba1a66..000000000 --- a/japicmp/src/main/java/japicmp/output/extapi/jpa/JpaAnalyzer.java +++ /dev/null @@ -1,28 +0,0 @@ -package japicmp.output.extapi.jpa; - -import japicmp.model.JApiAnnotation; -import japicmp.model.JApiClass; -import japicmp.output.extapi.jpa.model.JpaTable; - -import java.util.LinkedList; -import java.util.List; - -public class JpaAnalyzer { - public static final String JPA_ANNOTATION_ENTITY = "javax.persistence.Entity"; - public static final String JPA_ANNOTATION_TRANSIENT = "javax.persistence.Transient"; - - public List analyze(List classes) { - List jpaTables = new LinkedList<>(); - for (JApiClass jApiClass : classes) { - List annotations = jApiClass.getAnnotations(); - for (JApiAnnotation jApiAnnotation : annotations) { - String fullyQualifiedName = jApiAnnotation.getFullyQualifiedName(); - if (JPA_ANNOTATION_ENTITY.equals(fullyQualifiedName)) { - JpaTable jpaTable = new JpaTable(jApiClass, jApiAnnotation); - jpaTables.add(jpaTable); - } - } - } - return jpaTables; - } -} diff --git a/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaAttribute.java b/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaAttribute.java deleted file mode 100644 index 64de960a7..000000000 --- a/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaAttribute.java +++ /dev/null @@ -1,18 +0,0 @@ -package japicmp.output.extapi.jpa.model; - -import japicmp.model.JApiChangeStatus; - -public class JpaAttribute { - private final JApiChangeStatus changeStatus; - - public JpaAttribute(JApiChangeStatus changeStatus) { - this.changeStatus = evaluateChangeStatus(changeStatus); - } - - private JApiChangeStatus evaluateChangeStatus(JApiChangeStatus changeStatus) { - if (changeStatus == JApiChangeStatus.UNCHANGED) { - - } - return changeStatus; - } -} diff --git a/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaName.java b/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaName.java deleted file mode 100644 index 5af4cd0be..000000000 --- a/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaName.java +++ /dev/null @@ -1,36 +0,0 @@ -package japicmp.output.extapi.jpa.model; - -import japicmp.util.Optional; -import japicmp.model.JApiChangeStatus; -import japicmp.model.JApiHasChangeStatus; -import japicmp.util.OptionalHelper; - -import javax.xml.bind.annotation.XmlAttribute; - -public class JpaName implements JApiHasChangeStatus { - private final Optional newName; - private final Optional oldName; - private final JApiChangeStatus changeStatus; - - public JpaName(Optional oldName, Optional newName, JApiChangeStatus changeStatus) { - this.oldName = oldName; - this.newName = newName; - this.changeStatus = changeStatus; - } - - @Override - @XmlAttribute(name = "changeStatus") - public JApiChangeStatus getChangeStatus() { - return changeStatus; - } - - @XmlAttribute(name = "newName") - public String getNewName() { - return OptionalHelper.optionalToString(this.newName); - } - - @XmlAttribute(name = "oldName") - public String getOldName() { - return OptionalHelper.optionalToString(this.oldName); - } -} diff --git a/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaTable.java b/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaTable.java deleted file mode 100644 index 70a9a05d3..000000000 --- a/japicmp/src/main/java/japicmp/output/extapi/jpa/model/JpaTable.java +++ /dev/null @@ -1,205 +0,0 @@ -package japicmp.output.extapi.jpa.model; - -import japicmp.model.*; -import japicmp.output.extapi.jpa.JpaAnalyzer; -import japicmp.util.Optional; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import java.util.LinkedList; -import java.util.List; - -public class JpaTable { - private final List attributes = new LinkedList<>(); - private final JApiClass jApiClass; - private final JpaName jpaName; - private final JApiChangeStatus changeStatus; - - public JpaTable(JApiClass jApiClass, JApiAnnotation entityAnnotation) { - this.jApiClass = jApiClass; - this.jpaName = extractName(entityAnnotation, jApiClass); - extractAttributes(); - changeStatus = computeChangeStatus(); - } - - private JpaName extractName(JApiAnnotation entityAnnotation, JApiClass jApiClass) { - JApiChangeStatus changeStatusClass = jApiClass.getChangeStatus(); - String tableName = computeTablename(); - for (JApiAnnotationElement element : entityAnnotation.getElements()) { - if ("name".equals(element.getName())) { - JApiChangeStatus elementChangeStatus = element.getChangeStatus(); - switch (elementChangeStatus) { - case NEW: - String newName = removeQuotationMarks(element.getNewValue().get().toString()); - if (changeStatusClass == JApiChangeStatus.NEW) { - return new JpaName(Optional.absent(), Optional.of(newName), JApiChangeStatus.NEW); - } - if (tableName.equals(newName)) { - return new JpaName(Optional.of(newName), Optional.of(newName), JApiChangeStatus.UNCHANGED); - } else { - return new JpaName(Optional.of(tableName), Optional.of(newName), JApiChangeStatus.MODIFIED); - } - case REMOVED: - String oldName = removeQuotationMarks(element.getOldValue().get().toString()); - if (changeStatusClass == JApiChangeStatus.REMOVED) { - return new JpaName(Optional.of(oldName), Optional.absent(), JApiChangeStatus.REMOVED); - } - if (tableName.equals(oldName)) { - return new JpaName(Optional.of(oldName), Optional.of(oldName), JApiChangeStatus.UNCHANGED); - } else { - return new JpaName(Optional.of(oldName), Optional.of(tableName), JApiChangeStatus.MODIFIED); - } - case MODIFIED: - newName = removeQuotationMarks(element.getNewValue().get().toString()); - oldName = removeQuotationMarks(element.getOldValue().get().toString()); - return new JpaName(Optional.of(oldName), Optional.of(newName), JApiChangeStatus.MODIFIED); - case UNCHANGED: - newName = removeQuotationMarks(element.getNewValue().get().toString()); - return new JpaName(Optional.of(newName), Optional.of(newName), JApiChangeStatus.UNCHANGED); - } - } - break; - } - if (changeStatusClass == JApiChangeStatus.NEW) { - return new JpaName(Optional.absent(), Optional.of(tableName), JApiChangeStatus.NEW); - } else if (changeStatusClass == JApiChangeStatus.REMOVED) { - return new JpaName(Optional.of(tableName), Optional.absent(), JApiChangeStatus.REMOVED); - } - return new JpaName(Optional.of(tableName), Optional.of(tableName), JApiChangeStatus.UNCHANGED); - } - - private String removeQuotationMarks(String s) { - return s.replace("\"", ""); - } - - private JApiChangeStatus computeChangeStatus() { - JApiChangeStatus changeStatus = jApiClass.getChangeStatus(); - if (changeStatus == JApiChangeStatus.MODIFIED) { - changeStatus = JApiChangeStatus.UNCHANGED; - } - if (jpaName.getChangeStatus() != JApiChangeStatus.UNCHANGED) { - changeStatus = JApiChangeStatus.MODIFIED; - } - return changeStatus; - } - - private void extractAttributes() { - List fields = jApiClass.getFields(); - for (JApiField field : fields) { - Optional transientAnnotationOfFieldOptional = getTransientAnnotationOfField(field); - Optional transientAnnotationOfPropertyOptional = getTransientAnnotationOfProperty(field); - if (!transientAnnotationOfFieldOptional.isPresent() && !transientAnnotationOfPropertyOptional.isPresent()) { - JApiChangeStatus fieldChangeStatus = field.getChangeStatus(); - if (fieldChangeStatus == JApiChangeStatus.NEW) { - JpaAttribute jpaAttribute = new JpaAttribute(JApiChangeStatus.NEW); - } - } - } - } - - private Optional getTransientAnnotationOfField(JApiField field) { - Optional returnValue = Optional.absent(); - for (JApiAnnotation annotation : field.getAnnotations()) { - if (JpaAnalyzer.JPA_ANNOTATION_TRANSIENT.equals(annotation.getFullyQualifiedName())) { - returnValue = Optional.of(annotation); - break; - } - } - return returnValue; - } - - private Optional getTransientAnnotationOfProperty(JApiField field) { - Optional returnValue = Optional.absent(); - Optional propertyMethodOptional = getPropertyMethod(field); - if (propertyMethodOptional.isPresent()) { - JApiMethod propertyMethod = propertyMethodOptional.get(); - for (JApiAnnotation annotation : propertyMethod.getAnnotations()) { - if (JpaAnalyzer.JPA_ANNOTATION_TRANSIENT.equals(annotation.getFullyQualifiedName())) { - returnValue = Optional.of(annotation); - break; - } - } - } - return returnValue; - } - - private Optional getPropertyMethod(JApiField field) { - Optional propertyMethod = Optional.absent(); - String fieldName = field.getName(); - String getterName = "get" + (Character.isUpperCase(fieldName.charAt(0)) ? - fieldName : - fieldName.length() > 1 ? - Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1) : - Character.toUpperCase(fieldName.charAt(0))); - for (JApiMethod method : jApiClass.getMethods()) { - if (getterName.equals(method.getName())) { - propertyMethod = Optional.of(method); - break; - } - } - if (!propertyMethod.isPresent()) { - String isName = "is" + getterName.substring(3); - for (JApiMethod method : jApiClass.getMethods()) { - if (isName.equals(method.getName())) { - propertyMethod = Optional.of(method); - break; - } - } - } - return propertyMethod; - } - - @XmlElementWrapper(name = "attributes") - @XmlElement(name = "attribute") - public List getAttributes() { - return attributes; - } - - @XmlAttribute(name = "fullyQualifiedName") - public String getFullyQualifiedName() { - return jApiClass.getFullyQualifiedName(); - } - - public String computeTablename() { - String className = toClassName(jApiClass.getFullyQualifiedName()); - return toJpaName(className); - } - - static String toJpaName(String javaName) { - boolean lastCharWasUpperCase = true; - StringBuilder jpaName = new StringBuilder(); - for (int i = 0; i < javaName.length(); i++) { - char c = javaName.charAt(i); - if (Character.isUpperCase(c)) { - if (!lastCharWasUpperCase) { - jpaName.append("_"); - } - jpaName.append(c); - lastCharWasUpperCase = true; - } else { - jpaName.append(Character.toUpperCase(c)); - lastCharWasUpperCase = false; - } - } - return jpaName.toString(); - } - - private String toClassName(String className) { - String[] parts = className.split("\\."); - if (parts.length > 0) { - className = parts[parts.length - 1]; - } - return className; - } - - @XmlAttribute(name = "changeStatus") - public String getChangeStatus() { - return changeStatus.toString(); - } - - @XmlElement(name = "name") - public JpaName getJpaName() { - return this.jpaName; - } -}