Skip to content

Commit

Permalink
Eclipse 4.11 (M3) JDT Patch for Groovy-Eclipse: JDT commit ea4f416
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 23, 2019
1 parent 50e9290 commit c529461
Show file tree
Hide file tree
Showing 75 changed files with 1,971 additions and 431 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</license>

<requires>
<import feature="org.eclipse.jdt" version="3.17.0.v20190109-1800" patch="true"/>
<import feature="org.eclipse.jdt" version="3.17.0.v20190220-1800" patch="true"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#Thu Nov 04 13:38:23 EDT 2010
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
sp_cleanup.add_default_serial_version_id=true
Expand All @@ -14,10 +13,12 @@ sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
sp_cleanup.format_source_code=false
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.insert_inferred_type_arguments=false
sp_cleanup.make_local_variable_final=false
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
Expand All @@ -33,12 +34,15 @@ sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_trailing_whitespaces=false
sp_cleanup.remove_redundant_modifiers=false
sp_cleanup.remove_redundant_semicolons=true
sp_cleanup.remove_redundant_type_arguments=true
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=false
sp_cleanup.remove_unnecessary_nls_tags=false
sp_cleanup.remove_unused_imports=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
Expand All @@ -47,8 +51,10 @@ sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.update_ibm_copyright_to_current_year=true
sp_cleanup.use_anonymous_class_creation=false
sp_cleanup.use_blocks=false
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_lambda=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.core.tests.builder; singleton:=true
Bundle-Version: 3.10.400.qualifier
Bundle-Version: 3.10.500.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.core.tests.builder
Expand Down
4 changes: 2 additions & 2 deletions jdt-patch/e411/org.eclipse.jdt.core.tests.builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/org/documents/edl-v10.php
Contributors:
Igor Fedorenko - initial implementation
-->
Expand All @@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core.tests.builder</artifactId>
<version>3.10.400-SNAPSHOT</version>
<version>3.10.500-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/*******************************************************************************
* Copyright (c) 2019 Andrey Loskutov and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrey Loskutov - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.tests.builder;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.tests.util.Util;

/**
* Base class for testing builder related opened file leak tests, see bug 543506
*/
public abstract class AbstractLeakTest extends BuilderTests {

static boolean WINDOWS;
static boolean LINUX;
static boolean MAC;
static {
String os = System.getProperty("os.name").toLowerCase();
WINDOWS = os.contains("windows");
LINUX = os.contains("linux");
MAC = os.contains("mac");
}

public AbstractLeakTest(String name) {
super(name);
}

protected void testLeaksOnIncrementalBuild() throws Exception {
if(MAC) {
return;
}
internalTestUsedLibraryLeaks(IncrementalProjectBuilder.INCREMENTAL_BUILD);
}

protected void testLeaksOnCleanBuild() throws Exception {
if(MAC) {
return;
}
internalTestUsedLibraryLeaks(IncrementalProjectBuilder.CLEAN_BUILD);
}

protected void testLeaksOnFullBuild() throws Exception {
if(MAC) {
return;
}
internalTestUsedLibraryLeaks(IncrementalProjectBuilder.FULL_BUILD);
}

private void internalTestUsedLibraryLeaks(int kind) throws Exception {
String projectName = getName();
IPath projectPath = env.addProject(projectName, getCompatibilityLevel());
env.setOutputFolder(projectPath, "");
env.addExternalJars(projectPath, Util.getJavaClassLibs());
IPath internalJar = addInternalJar(projectPath);

createJavaFile(projectPath);

switch (kind) {
case IncrementalProjectBuilder.CLEAN_BUILD:
cleanBuild(projectName);
assertNotLeaked(internalJar);
break;
case IncrementalProjectBuilder.FULL_BUILD:
fullBuild(projectPath);
assertNotLeaked(internalJar);
break;
case IncrementalProjectBuilder.INCREMENTAL_BUILD:
incrementalBuild(projectPath);
changeJavaFile(projectPath);
incrementalBuild(projectPath);
assertNotLeaked(internalJar);
break;
default:
fail("Unexpected build kind: " + kind);
}
}

abstract String getCompatibilityLevel();

private IPath addInternalJar(IPath projectPath) throws IOException, JavaModelException {
IPath internalJar = addEmptyInternalJar(projectPath, "test.jar");
return internalJar;
}

private void createJavaFile(IPath projectPath) {
IPath path = env.addClass(projectPath, "a", "Other",
"package a;\n" +
"public class Other {\n" +
"}"
);
IFile file = env.getWorkspace().getRoot().getFile(path);
assertTrue("File should exists: " + path, file.exists());
}

private void changeJavaFile(IPath projectPath) throws Exception {
IPath path = env.addClass(projectPath, "a", "Other",
"package a;\n" +
"public class Other {\n" +
" // an extra comment \n" +
"}"
);
IFile file = env.getWorkspace().getRoot().getFile(path);
assertTrue("FIle should exists: " + path, file.exists());
}

private void assertNotLeaked(IPath path) throws Exception {
expectingNoProblems();
IFile file = env.getWorkspace().getRoot().getFile(path);
assertTrue("FIle should exists: " + path, file.exists());
if(WINDOWS) {
tryRemoveFile(file);
} else if (LINUX) {
checkOpenDescriptors(file);
}
}

private void tryRemoveFile(IFile file) {
// Note: this is a lame attempt to check for leaked file descriptor
// This works on Windows only, because windows does not allow to delete
// files opened for reading.
// On Linux we need something like lsof -p <my_process_id> | grep file name
try {
file.delete(true, null);
} catch (CoreException e) {
try {
// second attempt to avoid delays on teardown
Files.deleteIfExists(file.getLocation().toFile().toPath());
} catch (Exception e2) {
file.getLocation().toFile().delete();
// ignore
}
throw new IllegalStateException("File leaked during build: " + file, e);
}
assertFalse("File should be deleted: " + file, file.exists());
}

private void checkOpenDescriptors(IFile file) throws Exception {
List<String> openDescriptors = getOpenDescriptors();
assertFalse("Failed to read opened file descriptors", openDescriptors.isEmpty());
if(openDescriptors.contains(file.getLocation().toOSString())) {
throw new IllegalStateException("File leaked during build: " + file);
}
}

private static List<String> getOpenDescriptors() throws Exception {
int pid = getPid();
if (pid > 0) {
// -F n : to print only name column (note: all lines start with "n")
// -a : to "and" all following options
// -b :to avoid blocking calls
// -p <pid>: to select process with opened files
List<String> lines = readLsofLines("lsof -F n -a -p " + pid + " / -b ", true);
return lines;
}
return Collections.emptyList();
}

private static int getPid() throws Exception {
try (BufferedReader rdr = new BufferedReader(new FileReader("/proc/self/stat"));) {
return Integer.parseInt(new StringTokenizer(rdr.readLine()).nextToken());
}
}

private static List<String> readLsofLines(String cmd, boolean skipFirst) throws Exception {
List<String> lines = new ArrayList<>();
Process process = Runtime.getRuntime().exec(cmd);
try (BufferedReader rdr = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
if (skipFirst) {
rdr.readLine();
}
String line;
while((line = rdr.readLine())!= null) {
// remove "n" prefix from lsof output
if(line.startsWith("n")) {
line = line.substring(1);
}
if(line.trim().length() > 1) {
lines.add(line);
}
}
}
lines.sort(null);
return lines;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.builder;

import static org.eclipse.jdt.core.tests.util.AbstractCompilerTest.*;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
import junit.framework.*;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.tests.junit.extension.TestCase;
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
import org.eclipse.jdt.core.tests.util.TestVerifier;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.internal.compiler.Compiler;
import org.eclipse.jdt.core.compiler.CharOperation;

import junit.framework.Test;
import junit.framework.TestSuite;

/**
* Base class for Java image builder tests
Expand All @@ -50,7 +58,7 @@ protected void cleanBuild() {
env.cleanBuild();
this.debugRequestor.deactivate();
}

protected void cleanBuild(String name) {
this.debugRequestor.clearResult();
this.debugRequestor.activate();
Expand Down Expand Up @@ -536,18 +544,25 @@ private static Class[] getAllTestClasses() {
TestAttributeBuilderTests.class,
Bug530366Test.class,
Bug531382Test.class,
ParallelBuildTests.class
ParallelBuildTests.class,
LeakTestsBefore9.class,
};

if ((AbstractCompilerTest.getPossibleComplianceLevels() & AbstractCompilerTest.F_1_5) != 0) {
int length = classes.length;
System.arraycopy(classes, 0, classes = new Class[length+4], 0, length);
classes[length++] = Java50Tests.class;
classes[length++] = PackageInfoTest.class;
classes[length++] = ParticipantBuildTests.class;
classes[length++] = AnnotationDependencyTests.class;
List<Class<?>> list = new ArrayList<>(Arrays.asList(classes));
if (matchesCompliance(F_1_5)) {
list.add(Java50Tests.class);
list.add(PackageInfoTest.class);
list.add(ParticipantBuildTests.class);
list.add(AnnotationDependencyTests.class);
}
return classes;
if (matchesCompliance(F_9)) {
list.add(LeakTestsAfter9.class);
}
return list.toArray(new Class[0]);
}

static boolean matchesCompliance(int level) {
int complianceLevels = getPossibleComplianceLevels();
return complianceLevels >= level;
}

public static Test buildTestSuite(Class evaluationTestClass, long ordering) {
Expand Down Expand Up @@ -602,4 +617,18 @@ public static Test suite() {

return suite;
}

static IPath addEmptyInternalJar(IPath projectPath, String jarName) throws IOException, JavaModelException {
IProject project = env.getProject(projectPath);
String jarFile = project.getLocation().append(jarName).toOSString();
Util.createEmptyJar(jarFile, JavaCore.VERSION_1_4);
IPath jarPath = null;
try (FileInputStream fis = new FileInputStream(jarFile)) {
int length = fis.available();
byte[] jarContent = new byte[length];
fis.read(jarContent);
jarPath = env.addInternalJar(projectPath, jarName, jarContent);
}
return jarPath;
}
}
Loading

0 comments on commit c529461

Please sign in to comment.