28package com.jogamp.junit.util;
31import java.io.IOException;
32import java.net.URISyntaxException;
33import java.util.ArrayList;
35import java.util.Optional;
37import org.junit.Assert;
39import com.jogamp.common.net.Uri;
40import com.jogamp.common.util.JarUtil;
41import com.jogamp.common.util.VersionNumberString;
43import japicmp.cmp.JarArchiveComparator;
44import japicmp.cmp.JarArchiveComparatorOptions;
45import japicmp.config.Options;
46import japicmp.cmp.JApiCmpArchive;
47import japicmp.model.JApiChangeStatus;
48import japicmp.model.JApiClass;
49import japicmp.output.stdout.StdoutOutputGenerator;
50import japicmp.versioning.SemanticVersion;
80 NON_BACKWARD_COMPATIBLE
85 final Class<?> currentJarClazz,
final ClassLoader currentJarCL,
final VersionNumberString curVersionNumber,
86 final String excludesArgOption,
final boolean summaryOnly)
throws IllegalArgumentException, URISyntaxException, IOException
91 previousJar, preVersionNumber,
92 currentJarUri.
toFile(), curVersionNumber,
93 excludesArgOption, summaryOnly);
99 final String excludesArgOption,
final boolean summaryOnly)
throws IllegalArgumentException, IOException, URISyntaxException
101 final Options options = Options.newDefault();
102 options.setSemanticVersioning(
true);
103 options.setIgnoreMissingClasses(
true);
104 options.setReportOnlySummary(summaryOnly);
105 options.setOutputOnlyBinaryIncompatibleModifications(
true);
106 if(
null != excludesArgOption && excludesArgOption.length() > 0 ) {
107 options.addExcludeFromArgument(Optional.ofNullable(excludesArgOption),
false);
110 final JApiCmpArchive previous =
new JApiCmpArchive(previousJar, preVersionNumber.getVersionString());
111 final JApiCmpArchive current =
new JApiCmpArchive(currentJar, curVersionNumber.getVersionString());
112 final Optional<SemanticVersion> previousVersion = previous.getVersion().getSemanticVersion();
113 final Optional<SemanticVersion> currentVersion = current.getVersion().getSemanticVersion();
114 final JarArchiveComparatorOptions comparatorOptions = JarArchiveComparatorOptions.of(options);
115 final JarArchiveComparator jarArchiveComparator =
new JarArchiveComparator(comparatorOptions);
118 final List<JApiClass> jApiClasses1 = jarArchiveComparator.compare(previous, current);
119 final List<JApiClass> jApiClasses2 =
new ArrayList<JApiClass>(jApiClasses1.size());
120 for(
final JApiClass jApiClass : jApiClasses1) {
121 final boolean unchanged = jApiClass.getChangeStatus() == JApiChangeStatus.UNCHANGED && jApiClass.getChangeStatus() != JApiChangeStatus.MODIFIED;
123 jApiClasses2.add(jApiClass);
124 switch( detectedCompatibilityType ) {
125 case BACKWARD_COMPATIBLE_IMPLEMENTER:
126 if( !jApiClass.isBinaryCompatible() ) {
128 }
else if( !jApiClass.isSourceCompatible() ) {
134 case BACKWARD_COMPATIBLE_SOURCE:
135 if( !jApiClass.isBinaryCompatible() ) {
137 }
else if( !jApiClass.isSourceCompatible() ) {
141 case BACKWARD_COMPATIBLE_BINARY:
142 if( !jApiClass.isBinaryCompatible() ) {
146 case NON_BACKWARD_COMPATIBLE:
153 final int comp = detectedCompatibilityType.compareTo(expectedCompatibilityType);
154 final boolean compOK = 0 >= comp;
158 }
else if ( 0 == comp ) {
164 System.err.println(
"Semantic Version Test (japicmp)");
165 System.err.println(
" Previous version: "+previousVersion+
" - "+previousJar.toString());
166 System.err.println(
" Current version: "+currentVersion+
" - "+currentJar.toString());
167 System.err.println(
" Compat. expected: "+expectedCompatibilityType);
168 System.err.println(
" Compat. detected: "+detectedCompatibilityType);
169 System.err.println(
" Compat. result: detected "+compS+
" expected -> "+(compOK ?
"OK" :
"ERROR"));
172 resS =
" Current version "+curVersionNumber+
" is "+expectedCompatibilityType+
" to previous version "+preVersionNumber+
", actually "+detectedCompatibilityType;
174 resS =
" Current version "+curVersionNumber+
" is not "+expectedCompatibilityType+
" to previous version "+preVersionNumber+
", but "+detectedCompatibilityType;
176 System.err.println(resS);
177 System.err.printf(
"%n%n");
179 final StdoutOutputGenerator out =
new StdoutOutputGenerator(options, jApiClasses2);
180 System.err.println(out.generate());
185 Assert.assertTrue(resS, compOK);
This class implements an immutable Uri as defined by RFC 2396.
final File toFile()
If this instance is a file scheme, implementation decodes [ "//"+authority ] + path,...
final Uri getContainedUri()
If this instance's schemeSpecificPart contains a Uri itself, a sub-Uri, return schemeSpecificPart + #...
static Uri getJarUri(final String clazzBinName, final ClassLoader cl)
The Class's "com.jogamp.common.GlueGenVersion" Uri jar:sub_protocol:/some/path/gluegen-rt....
VersionNumber specialization, holding the versionString this instance is derived from.
static void testVersion2(final CompatibilityType expectedCompatibilityType, final File previousJar, final VersionNumberString preVersionNumber, final Class<?> currentJarClazz, final ClassLoader currentJarCL, final VersionNumberString curVersionNumber, final String excludesArgOption, final boolean summaryOnly)
static void testVersion2(final CompatibilityType expectedCompatibilityType, final File previousJar, final VersionNumberString preVersionNumber, final File currentJar, final VersionNumberString curVersionNumber, final String excludesArgOption, final boolean summaryOnly)
Library compatibility type.
NON_BACKWARD_COMPATIBLE
Contains non binary compatible changes.
BACKWARD_COMPATIBLE_SOURCE
Only added and deprecated changes, i.e.
BACKWARD_COMPATIBLE_IMPLEMENTER
No (public) changes.
BACKWARD_COMPATIBLE_BINARY
Contains binary compatible changes, but may not be fully source compatible and may contain changed va...