Skip to content

Commit

Permalink
[MNGECLIPSE-2144] New versions of the maven-resources-plugin are brok…
Browse files Browse the repository at this point in the history
…en on Windows
  • Loading branch information
bentmann committed Mar 16, 2010
1 parent f73d498 commit 3881e4b
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 2 deletions.
Expand Up @@ -25,7 +25,16 @@ public void testScanner() throws Exception {
IProject project = importProject("projects/MNGECLIPSE-2144/pom.xml");

EclipseBuildContext context = new EclipseBuildContext(project, new HashMap<String, Object>());
Scanner scanner = context.newScanner(new File(project.getLocation().toFile(), "src/main/resources"), true);
Scanner scanner;

scanner = context.newScanner(new File(project.getLocation().toFile(), "src/main/resources"), true);
checkScanner(scanner);

scanner = context.newScanner(new File(project.getLocation().toFile(), "src/main/resources"), false);
checkScanner(scanner);
}

private void checkScanner(Scanner scanner) {
// both forward and backward slashes must be understood as separators
scanner.setIncludes(new String[] {"sub/dir\\file.txt"});
scanner.scan();
Expand Down
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* 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
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.maven.ide.eclipse.builder;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.codehaus.plexus.util.Scanner;
import org.eclipse.core.resources.IProject;
import org.maven.ide.eclipse.tests.common.AbstractMavenProjectTestCase;


@SuppressWarnings("restriction")
public class EclipseIncrementalBuildContextTest extends AbstractMavenProjectTestCase {

public void testScanner() throws Exception {
IProject project = importProject("projects/MNGECLIPSE-2144/pom.xml");

ResourceDeltaStub delta = new ResourceDeltaStub(project);
ResourceDeltaStub child = delta.addChild(new ResourceDeltaStub(project.getFolder("src")));
child = child.addChild(new ResourceDeltaStub(project.getFolder("src/main")));
child = child.addChild(new ResourceDeltaStub(project.getFolder("src/main/resources")));
child = child.addChild(new ResourceDeltaStub(project.getFolder("src/main/resources/sub")));
child = child.addChild(new ResourceDeltaStub(project.getFolder("src/main/resources/sub/dir")));
child = child.addChild(new ResourceDeltaStub(project.getFile("src/main/resources/sub/dir/file.txt")));

EclipseIncrementalBuildContext context = new EclipseIncrementalBuildContext(delta, new HashMap<String, Object>());
Scanner scanner;

scanner = context.newScanner(new File(project.getLocation().toFile(), "src/main/resources"), true);
checkScanner(scanner);

scanner = context.newScanner(new File(project.getLocation().toFile(), "src/main/resources"), false);
checkScanner(scanner);
}

private void checkScanner(Scanner scanner) {
// both forward and backward slashes must be understood as separators
scanner.setIncludes(new String[] {"sub/dir\\file.txt"});
scanner.scan();

List<String> included = Arrays.asList(scanner.getIncludedFiles());
assertTrue(included.toString(), included.contains("sub" + File.separator + "dir" + File.separator + "file.txt"));
}

}
@@ -0,0 +1,128 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* 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
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.maven.ide.eclipse.builder;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject;


class ResourceDeltaStub extends PlatformObject implements IResourceDelta {

private IResource resource;

private int kind;

private int flags;

private List<IResourceDelta> children = new ArrayList<IResourceDelta>();

public ResourceDeltaStub(IResource resource) {
this.resource = resource;
kind = IResourceDelta.CHANGED;
flags = IResourceDelta.CONTENT;
}

public <T extends IResourceDelta> T addChild(T child) {
children.add(child);
return child;
}

public void accept(IResourceDeltaVisitor visitor) throws CoreException {
accept(visitor, 0);
}

public void accept(IResourceDeltaVisitor visitor, boolean includePhantoms) throws CoreException {
accept(visitor, includePhantoms ? IContainer.INCLUDE_PHANTOMS : 0);
}

public void accept(IResourceDeltaVisitor visitor, int memberFlags) throws CoreException {
if(!visitor.visit(this)) {
return;
}
for(IResourceDelta child : children) {
child.accept(visitor, memberFlags);
}
}

public IResourceDelta findMember(IPath path) {
int segmentCount = path.segmentCount();
if(segmentCount == 0) {
return this;
}

String segment = path.segment(0);
for(IResourceDelta child : children) {
if(child.getFullPath().lastSegment().equals(segment)) {
return child.findMember(path.removeFirstSegments(1));
}
}

return null;
}

public IResourceDelta[] getAffectedChildren() {
return getAffectedChildren(ADDED | REMOVED | CHANGED, IResource.NONE);
}

public IResourceDelta[] getAffectedChildren(int kindMask) {
return getAffectedChildren(kindMask, IResource.NONE);
}

public IResourceDelta[] getAffectedChildren(int kindMask, int memberFlags) {
List<IResourceDelta> result = new ArrayList<IResourceDelta>();
for(IResourceDelta child : children) {
if((child.getKind() & kindMask) != 0) {
result.add(child);
}
}
return result.toArray(new IResourceDelta[result.size()]);
}

public int getKind() {
return kind;
}

public int getFlags() {
return flags;
}

public IPath getFullPath() {
return resource.getFullPath();
}

public IPath getProjectRelativePath() {
return resource.getProjectRelativePath();
}

public IMarkerDelta[] getMarkerDeltas() {
return new IMarkerDelta[0];
}

public IPath getMovedFromPath() {
return null;
}

public IPath getMovedToPath() {
return null;
}

public IResource getResource() {
return resource;
}

}
@@ -1,3 +1,11 @@
/*******************************************************************************
* Copyright (c) 2008 Sonatype, Inc.
* 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
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/

package org.maven.ide.eclipse.builder;

import java.io.File;
Expand Down Expand Up @@ -76,7 +84,7 @@ protected boolean isInteresting(IResourceDelta delta) {
}

protected String getRelativePath(IResourceDelta delta) {
return delta.getFullPath().removeFirstSegments(this.delta.getFullPath().segmentCount()).toPortableString();
return delta.getFullPath().removeFirstSegments(this.delta.getFullPath().segmentCount()).toOSString();
}

public File getBasedir() {
Expand Down

0 comments on commit 3881e4b

Please sign in to comment.