Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhofer committed Apr 17, 2010
2 parents d27842c + abfedd3 commit c99d1c1
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 173 deletions.
2 changes: 1 addition & 1 deletion ecobertura.core/META-INF/MANIFEST.MF
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: eCobertura Core
Bundle-SymbolicName: ecobertura.core;singleton:=true
Bundle-Version: 0.9.3.qualifier
Bundle-Version: 0.9.4.qualifier
Bundle-Activator: ecobertura.core.CorePlugin
Bundle-Localization: OSGI-INF/l10n/bundle
Bundle-Vendor: jmhofer
Expand Down
Expand Up @@ -85,7 +85,7 @@ class CoberturaWrapper extends ICoberturaWrapper {
CoverageDataFileHandler.loadCoverageData(coberturaFile)
}

override def resetProjectData= {
override def resetProjectData = {
defaultCoberturaFile.delete
initializeCoberturaProjectData
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ trait ClassCoverage extends CoverageData {
def sourceFileName: String
def lines: List[LineCoverage]

override def toString = String.format("ClassCoverage(%s)%s", name, super.toString)
override def toString = "ClassCoverage(%s, %s)%s".format(name, sourceFileName, super.toString)
}

class CoberturaClassData(classData: ClassData) extends ClassCoverage {
Expand Down
Expand Up @@ -23,10 +23,12 @@ import java.util.Arrays
import java.util.logging.Logger

import org.eclipse.core.runtime.IPath
import org.eclipse.core.runtime.Path
import org.eclipse.debug.core.ILaunchConfiguration
import org.eclipse.jdt.launching._

import _root_.ecobertura.core.cobertura.CoberturaWrapper;
import _root_.ecobertura.core.CorePlugin
import _root_.ecobertura.core.cobertura.CoberturaWrapper

object CoverageClasspathProvider {
val ID = "ecobertura.core.launching.coverageClasspathProvider" //$NON-NLS-1$
Expand Down Expand Up @@ -56,13 +58,35 @@ class CoverageClasspathProvider extends IRuntimeClasspathProvider {
JavaRuntime.newArchiveRuntimeClasspathEntry(pathToCoberturaJar)
}

logger fine "resolving classpath..."
logger.fine("resolving classpath...")
val resolvedEntries = wrappedProvider.get.resolveClasspath(entries, configuration)
logger.fine("resolved entries: " + resolvedEntries.mkString)

val resolvedEntriesWithCoveredClasses = substituteProjectClassesByCoveredClasses(resolvedEntries)
val resolvedEntriesWithCobertura = Arrays.copyOf(
resolvedEntries, resolvedEntries.length + 1)
resolvedEntriesWithCoveredClasses, resolvedEntriesWithCoveredClasses.size + 1)
resolvedEntriesWithCobertura(resolvedEntries.size) = coberturaEntry
logger.fine("resolved entries: " + resolvedEntries)

logger.fine("resolved entries with cobertura: " + resolvedEntriesWithCobertura.mkString)

resolvedEntriesWithCobertura
}

private def substituteProjectClassesByCoveredClasses(resolvedEntries: Array[IRuntimeClasspathEntry]) = {
for {
i <- 0 until resolvedEntries.size
entry = resolvedEntries(i)
if entry.getClasspathProperty == IRuntimeClasspathEntry.USER_CLASSES &&
entry.getType == IRuntimeClasspathEntry.PROJECT
} resolvedEntries(i) = adaptedProjectClassesEntry(entry)

resolvedEntries
}

private def adaptedProjectClassesEntry(projectClasses: IRuntimeClasspathEntry) = {
logger.fine("adapting %s".format(projectClasses.getLocation))
val newPath = new Path(CorePlugin.instance.pluginState.instrumentedClassesDirectory.getAbsolutePath)
logger.fine("new path: %s".format(newPath.toString))
JavaRuntime.newArchiveRuntimeClasspathEntry(newPath)
}
}
Expand Up @@ -46,7 +46,7 @@ class LaunchInstrumenter(configuration: ILaunchConfiguration) {
CoberturaWrapper.get.resetProjectData
instrumentClasspath
CoberturaWrapper.get.saveProjectDataToDefaultFile
addCoberturaToClasspath
addCoberturaAndCoveredClassesToClasspath
addDatafileSystemProperty

private def instrumentClasspath = {
Expand Down Expand Up @@ -79,12 +79,14 @@ class LaunchInstrumenter(configuration: ILaunchConfiguration) {
if (containsUserClassesFromProject(classpathEntry)) {
val userClasspath = classpathEntry.getLocation
logger.fine(String format ("instrumenting classes within %s", userClasspath))
instrumentFilesWithin(new File(userClasspath))
CorePlugin.instance.pluginState.copyClassesFrom(new File(userClasspath))
instrumentFilesWithin(CorePlugin.instance.pluginState.instrumentedClassesDirectory)

} else logger.fine(String.format("skipping %s", classpathEntry.getLocation))
})
}

private def addCoberturaToClasspath = {
private def addCoberturaAndCoveredClassesToClasspath = {
configWC.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
CoverageClasspathProvider.ID)
CoverageClasspathProvider.wrap(JavaRuntime.getClasspathProvider(configuration))
Expand Down
111 changes: 74 additions & 37 deletions ecobertura.core/src/main/scala/ecobertura/core/state/PluginState.scala
@@ -1,37 +1,74 @@
/*
* This file is part of eCobertura.
*
* Copyright (c) 2009, 2010 Joachim Hofer
* All rights reserved.
*
* eCobertura is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* eCobertura is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with eCobertura. If not, see <http://www.gnu.org/licenses/>.
*/
package ecobertura.core.state

import java.io.File
import org.eclipse.core.runtime.IPath

object PluginState {
def initialize(stateLocation: IPath) = new PluginState(stateLocation)
}

class PluginState(stateLocation: IPath) {
val instrumentationDataDirectory = new File(stateLocation.toFile, "cobertura")
instrumentationDataDirectory.mkdirs

def cleanUp = {
instrumentationDataDirectory.listFiles.map(_.delete)
instrumentationDataDirectory.delete
}
}
/*
* This file is part of eCobertura.
*
* Copyright (c) 2009, 2010 Joachim Hofer
* All rights reserved.
*
* eCobertura is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* eCobertura is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with eCobertura. If not, see <http://www.gnu.org/licenses/>.
*/
package ecobertura.core.state
import java.io._

import org.eclipse.core.runtime.IPath

object PluginState {
def initialize(stateLocation: IPath) = new PluginState(stateLocation)
}

class PluginState(stateLocation: IPath) {
val instrumentationDataDirectory = new File(stateLocation.toFile, "cobertura")
val instrumentedClassesDirectory = new File(stateLocation.toFile, "bin")

instrumentationDataDirectory.mkdirs
instrumentedClassesDirectory.mkdirs

def cleanUp = {
deleteRecursively(instrumentationDataDirectory)
deleteRecursively(instrumentedClassesDirectory)
}

private def deleteRecursively(file: File) : Unit = {
if (file.isFile) file.delete
else {
file.listFiles.foreach (deleteRecursively(_))
file.delete
}
}

def copyClassesFrom(source: File) = {
deleteRecursively(instrumentedClassesDirectory)
copyRecursively(source, instrumentedClassesDirectory)
}

private def copyRecursively(source: File, destination: File) : Unit = {
if (source.isFile) copyFile(source, destination)
else {
if (!destination.exists) destination.mkdirs
source.list.foreach { file =>
copyRecursively(new File(source, file), new File(destination, file))
}
}
}

private def copyFile(source: File, destination: File) = {
val sourceStream = new FileInputStream(source)
val destinationStream = new FileOutputStream(destination)
val buffer = new Array[Byte](4096)
var bytesRead = sourceStream.read(buffer)
while (bytesRead >= 0) {
destinationStream.write(buffer, 0, bytesRead)
bytesRead = sourceStream.read(buffer)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions ecobertura.feature/feature.xml
Expand Up @@ -2,12 +2,14 @@
<feature
id="ecobertura"
label="eCobertura"
version="0.9.3.qualifier"
version="0.9.4.qualifier"
provider-name="jmhofer"
plugin="ecobertura.ui">

<description url="http://github.com/jmhofer/eCobertura">
eCobertura is a free Eclipse plug-in for Cobertura (a Java code coverage reporting tool based on jcoverage 1.0.5). See the eCobertura web page for more details.
<description url="http://ecobertura.johoop.de">
eCobertura is a free Eclipse plug-in for Cobertura (a Java code
coverage reporting tool based on jcoverage 1.0.5). See the eCobertura
web page for more details.
</description>

<copyright>
Expand Down
2 changes: 1 addition & 1 deletion ecobertura.pde/category.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature url="features/ecobertura_0.9.3.qualifier.jar" id="ecobertura" version="0.9.3.qualifier">
<feature url="features/ecobertura_0.9.4.qualifier.jar" id="ecobertura" version="0.9.4.qualifier">
<category name="eCobertura"/>
</feature>
<category-def name="eCobertura" label="eCobertura Code Coverage"/>
Expand Down
5 changes: 3 additions & 2 deletions ecobertura.ui/META-INF/MANIFEST.MF
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: eCobertura UI
Bundle-SymbolicName: ecobertura.ui;singleton:=true
Bundle-Version: 0.9.3.qualifier
Bundle-Version: 0.9.4.qualifier
Bundle-Activator: ecobertura.ui.UIPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand All @@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt.launching,
org.eclipse.jdt.ui,
org.eclipse.core.expressions,
org.eclipse.ui.ide
org.eclipse.ui.ide,
org.eclipse.search
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Vendor: jmhofer

This file was deleted.

@@ -0,0 +1,65 @@
/*
* This file is part of eCobertura.
*
* Copyright (c) 2010 Joachim Hofer
* All rights reserved.
*
* eCobertura is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* eCobertura is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with eCobertura. If not, see <http://www.gnu.org/licenses/>.
*/
package ecobertura.ui.util

import java.util.logging._
import java.util.regex.Pattern

import org.eclipse.core.resources._
import org.eclipse.search.core.text._

import ecobertura.ui.views.session.CoverageSessionClass

object SourceFileFinder {
val logger = Logger.getLogger("ecobertura.ui.util")
val searchEngine = TextSearchEngine.create
val everythingPattern = Pattern.compile(".*")

def fromSourceFileName(sourceFileName: String) = new SourceFileFinder(sourceFileName)
}

class SourceFileFinder(sourceFileName: String) {
import SourceFileFinder._

logger.fine("trying to find %s".format(sourceFileName))
val workspaceRoot = ResourcesPlugin.getWorkspace.getRoot
val fileSearchPattern = Pattern.compile(Pattern.quote(sourceFileName))
val scope = TextSearchScope.newSearchScope(Array[IResource](workspaceRoot),
fileSearchPattern, false)

def find(callback: IFile => Unit) = {
searchEngine.search(scope, new SearchHandler(callback), everythingPattern, null)
}

class SearchHandler(callback: IFile => Unit) extends TextSearchRequestor {
private var matchFound = false

override def acceptFile(file: IFile) = {
logger.fine("file found: %s".format(file.toString))
matchFound = true
callback(file)
false
}

override def endReporting = {
if (!matchFound) logger.fine("no match found")
}
}
}

0 comments on commit c99d1c1

Please sign in to comment.