This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SF #3489951: Don't process class files in team provider folders.
- Loading branch information
Showing
5 changed files
with
226 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
...eclemma.core/src/com/mountainminds/eclemma/internal/core/analysis/ResourceTreeWalker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2006, 2012 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Marc R. Hoffmann - initial API and implementation | ||
* | ||
******************************************************************************/ | ||
package com.mountainminds.eclemma.internal.core.analysis; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.eclipse.core.resources.IContainer; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IPath; | ||
import org.jacoco.core.analysis.Analyzer; | ||
|
||
/** | ||
* Internal utility to walk through a resource tree and identify all class | ||
* files. | ||
*/ | ||
class ResourceTreeWalker { | ||
|
||
private final Analyzer analyzer; | ||
|
||
public ResourceTreeWalker(Analyzer analyzer) { | ||
this.analyzer = analyzer; | ||
} | ||
|
||
public void walk(IResource resource) throws CoreException, IOException { | ||
if (resource.getType() == IResource.FILE) { | ||
final IFile file = (IFile) resource; | ||
final InputStream in = file.getContents(true); | ||
try { | ||
analyzer.analyzeArchive(in); | ||
} finally { | ||
in.close(); | ||
} | ||
} else { | ||
walkResource(resource); | ||
} | ||
} | ||
|
||
private void walkResource(IResource resource) throws CoreException, | ||
IOException { | ||
switch (resource.getType()) { | ||
case IResource.FILE: | ||
if (resource.getName().endsWith(".class")) { //$NON-NLS-1$ | ||
final IFile file = (IFile) resource; | ||
final InputStream in = file.getContents(true); | ||
try { | ||
analyzer.analyzeAll(in); | ||
} finally { | ||
in.close(); | ||
} | ||
} | ||
break; | ||
case IResource.FOLDER: | ||
case IResource.PROJECT: | ||
// Do not traverse into folders like ".svn" | ||
if (isJavaIdentifier(resource.getName())) { | ||
final IContainer container = (IContainer) resource; | ||
for (final IResource child : container.members()) { | ||
walkResource(child); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
|
||
public void walk(IPath path) throws IOException { | ||
final File file = path.toFile(); | ||
if (file.isFile()) { | ||
final InputStream in = open(file); | ||
try { | ||
analyzer.analyzeArchive(in); | ||
} finally { | ||
in.close(); | ||
} | ||
} else { | ||
walkFile(file); | ||
} | ||
} | ||
|
||
private void walkFile(File file) throws IOException { | ||
if (file.isFile()) { | ||
if (file.getName().endsWith(".class")) { //$NON-NLS-1$ | ||
final InputStream in = open(file); | ||
try { | ||
analyzer.analyzeAll(in); | ||
} finally { | ||
in.close(); | ||
} | ||
} | ||
} else { | ||
// Do not traverse into folders like ".svn" | ||
if (isJavaIdentifier(file.getName())) { | ||
for (final File child : file.listFiles()) { | ||
walkFile(child); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private BufferedInputStream open(final File file) | ||
throws FileNotFoundException { | ||
return new BufferedInputStream(new FileInputStream(file)); | ||
} | ||
|
||
private boolean isJavaIdentifier(String name) { | ||
for (int i = 0; i < name.length(); i++) { | ||
final char c = name.charAt(i); | ||
if (i == 0) { | ||
if (!Character.isJavaIdentifierStart(c)) { | ||
return false; | ||
} | ||
} else { | ||
if (!Character.isJavaIdentifierPart(c)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters