Skip to content

Commit

Permalink
Simplify api tools suites setup
Browse files Browse the repository at this point in the history
There is no way tests could be run on pre Java 8 as ecj can not generate
such bytecode anymore. Thus all these "conditional" additions are just
noise and clutter the codebase.
  • Loading branch information
akurtakov committed Oct 10, 2024
1 parent f78c298 commit d2f62b7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.eclipse.pde.api.tools.internal.util.Util;
import org.eclipse.pde.api.tools.model.tests.TestSuiteHelper;
import org.eclipse.pde.api.tools.tests.util.FileUtils;
import org.eclipse.pde.api.tools.tests.util.ProjectUtils;
import org.eclipse.pde.internal.core.ICoreConstants;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.natures.PluginProject;
Expand Down Expand Up @@ -1036,12 +1035,8 @@ private static Class<?>[] getAllTestClasses() {
classes.add(LeakTest.class);
classes.add(TagTest.class);
classes.add(AnnotationTest.class);
if (ProjectUtils.isJava7Compatible()) {
classes.add(Java7UsageTest.class);
}
if (ProjectUtils.isJava8Compatible()) {
classes.add(Java8UsageTest.class);
}
classes.add(Java7UsageTest.class);
classes.add(Java8UsageTest.class);
return classes.toArray(new Class[classes.size()]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2018 IBM Corporation and others.
* Copyright (c) 2013, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -25,7 +25,6 @@
import org.eclipse.pde.api.tools.builder.tests.ApiProblem;
import org.eclipse.pde.api.tools.builder.tests.ApiTestingEnvironment;
import org.eclipse.pde.api.tools.model.tests.TestSuiteHelper;
import org.eclipse.pde.api.tools.tests.util.ProjectUtils;

import junit.framework.Test;
import junit.framework.TestSuite;
Expand Down Expand Up @@ -76,11 +75,9 @@ private static Class<?>[] getAllTestClasses() {
classes.add(ValidEnumAnnotationsTests.class);
classes.add(FieldAnnotationTest.class);
classes.add(MethodAnnotationTest.class);
if (ProjectUtils.isJava8Compatible()) {
classes.add(InvalidJava8InterfaceAnnotationTests.class);
classes.add(ValidJava8InterfaceAnnotationTests.class);
classes.add(Java8TypeAnnotationTests.class);
}
classes.add(InvalidJava8InterfaceAnnotationTests.class);
classes.add(ValidJava8InterfaceAnnotationTests.class);
classes.add(Java8TypeAnnotationTests.class);

return classes.toArray(new Class<?>[classes.size()]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2018 IBM Corporation and others.
* Copyright (c) 2014, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -22,7 +22,6 @@
import org.eclipse.pde.api.tools.internal.problems.ApiProblemFactory;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem;
import org.eclipse.pde.api.tools.tests.util.ProjectUtils;

import junit.framework.Test;
import junit.framework.TestSuite;
Expand Down Expand Up @@ -65,9 +64,7 @@ private static Class<?>[] getAllTestClasses() {
tests.add(ValidDefaultMethodAnnotationTests.class);
tests.add(InvalidInterfaceMethodAnnotationTests.class);
tests.add(ValidInterfaceMethodAnnotationTests.class);
if (ProjectUtils.isJava8Compatible()) {
tests.add(InvalidDefaultMethodAnnotationTests.class);
}
tests.add(InvalidDefaultMethodAnnotationTests.class);
return tests.toArray(new Class<?>[tests.size()]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2018 IBM Corporation and others.
* Copyright (c) 2008, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -24,7 +24,6 @@
import org.eclipse.pde.api.tools.builder.tests.ApiProblem;
import org.eclipse.pde.api.tools.builder.tests.ApiTestingEnvironment;
import org.eclipse.pde.api.tools.model.tests.TestSuiteHelper;
import org.eclipse.pde.api.tools.tests.util.ProjectUtils;

import junit.framework.Test;
import junit.framework.TestSuite;
Expand Down Expand Up @@ -74,10 +73,8 @@ private static Class<?>[] getAllTestClasses() {
classes.add(ValidAnnotationTagTests.class);
classes.add(InvalidAnnotationTagTests.class);
classes.add(InvalidDuplicateTagsTests.class);
if (ProjectUtils.isJava8Compatible()) {
classes.add(ValidJava8InterfaceTagTests.class);
classes.add(InvalidJava8InterfaceTagTests.class);
}
classes.add(ValidJava8InterfaceTagTests.class);
classes.add(InvalidJava8InterfaceTagTests.class);

return classes.toArray(new Class<?>[classes.size()]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2018 IBM Corporation and others.
* Copyright (c) 2008, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -26,7 +26,6 @@
import org.eclipse.pde.api.tools.builder.tests.ApiProblem;
import org.eclipse.pde.api.tools.builder.tests.ApiTestingEnvironment;
import org.eclipse.pde.api.tools.model.tests.TestSuiteHelper;
import org.eclipse.pde.api.tools.tests.util.ProjectUtils;

import junit.framework.Test;
import junit.framework.TestSuite;
Expand Down Expand Up @@ -214,13 +213,11 @@ private static Class<?>[] getAllTestClasses() {
classes.add(UnusedApiProblemFilterTests.class);
classes.add(DependentUsageTests.class);
classes.add(FragmentUsageTests.class);
if (ProjectUtils.isJava5Compatible()) {
classes.add(Java5FieldUsageTests.class);
classes.add(Java5MethodUsageTests.class);
classes.add(Java5ClassUsageTests.class);
classes.add(AnnotationUsageTests.class);
// classes.add(EnumUsageTests.class);
}
classes.add(Java5FieldUsageTests.class);
classes.add(Java5MethodUsageTests.class);
classes.add(Java5ClassUsageTests.class);
classes.add(AnnotationUsageTests.class);
// classes.add(EnumUsageTests.class);
return classes.toArray(new Class[classes.size()]);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2021 IBM Corporation and others.
* Copyright (c) 2007, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -49,7 +49,6 @@
import org.eclipse.pde.api.tools.internal.search.IReferenceCollection;
import org.eclipse.pde.api.tools.internal.search.UseScanReferences;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.eclipse.pde.api.tools.tests.util.ProjectUtils;
import org.junit.Assert;
import org.osgi.framework.Bundle;

Expand All @@ -61,22 +60,15 @@
public class TestSuiteHelper {

/**
* Computes the compile options to use. Currently this only changes if we
* are running the tests on Java 8.
* Computes the compile options to use. Currently this sets params as if
* running the tests on Java 8.
*
* @return the array of compiler options to use
* @since 1.0.400
*/
public static String[] getCompilerOptions() {
ArrayList<String> args = new ArrayList<>();
if (ProjectUtils.isJava8Compatible()) {
args.add("-1.8"); //$NON-NLS-1$
} else {
args.add("-1.5"); //$NON-NLS-1$
}
args.add("-preserveAllLocals"); //$NON-NLS-1$
args.add("-nowarn"); //$NON-NLS-1$
return args.toArray(new String[] {});
List<String> args = List.of("-1.8", "-preserveAllLocals", "-nowarn"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return args.toArray(String[]::new);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,95 +66,6 @@ public static IBundleProjectService getBundleProjectService() {
return PDECore.getDefault().acquireService(IBundleProjectService.class);
}

/**
* Returns if the currently running VM is version compatible with Java 7
*
* @return <code>true</code> if a Java 7 (or greater) VM is running
* <code>false</code> otherwise
*/
public static boolean isJava7Compatible() {
return isCompatible(7);
}

/**
* Returns if the currently running VM is version compatible with Java 6
*
* @return <code>true</code> if a Java 6 (or greater) VM is running
* <code>false</code> otherwise
*/
public static boolean isJava6Compatible() {
return isCompatible(6);
}

/**
* Returns if the currently running VM is version compatible with Java 5
*
* @return <code>true</code> if a Java 5 (or greater) VM is running
* <code>false</code> otherwise
*/
public static boolean isJava5Compatible() {
return isCompatible(5);
}

/**
* Returns if the currently running VM is version compatible with Java 8
*
* @return <code>true</code> if a Java 8 (or greater) VM is running
* <code>false</code> otherwise
*/
public static boolean isJava8Compatible() {
return isCompatible(8);
}

/**
* Returns if the currently running VM is version compatible with Java 9
*
* @return <code>true</code> if a Java 9 (or greater) VM is running
* <code>false</code> otherwise
*/
public static boolean isJava9Compatible() {
return isCompatible(9);
}

/**
* Returns if the current running system is compatible with the given Java minor
* version
*
* @param ver
* the version to test - either 4, 5, 6 , 7 or 8
* @return <code>true</code> if compatible <code>false</code> otherwise
*/
static boolean isCompatible(int ver) {
String version = System.getProperty("java.specification.version"); //$NON-NLS-1$
if (version != null) {
String[] nums = version.split("\\."); //$NON-NLS-1$
if (nums.length == 2) {
try {
int major = Integer.parseInt(nums[0]);
int minor = Integer.parseInt(nums[1]);
if (major >= 1) {
if (minor >= ver) {
return true;
}
}
} catch (NumberFormatException e) {
}
}
if (nums.length == 1) {
// java 9 and above
try {
int major = Integer.parseInt(nums[0]);
if (major >= ver) {
return true;
}

} catch (NumberFormatException e) {
}
}
}
return false;
}

/**
* Crate a plug-in project with the given name
*
Expand Down

0 comments on commit d2f62b7

Please sign in to comment.