-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHRINKRES-281 Format processor for java.nio.file.Path (#126)
* Adding format processor for java.nio.file.Path * Fixing parameter validation for existing format implementations - getClass() would always return an instance of Class; instead the passed class object itself must be checked
- Loading branch information
1 parent
bcc428e
commit df5f9b4
Showing
5 changed files
with
63 additions
and
10 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
...main/resources/META-INF/services/org.jboss.shrinkwrap.resolver.spi.format.FormatProcessor
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
org.jboss.shrinkwrap.resolver.spi.format.FileFormatProcessor | ||
org.jboss.shrinkwrap.resolver.spi.format.URLFormatProcessor | ||
org.jboss.shrinkwrap.resolver.spi.format.InputStreamFormatProcessor | ||
org.jboss.shrinkwrap.resolver.spi.format.PathFormatProcessor | ||
org.jboss.shrinkwrap.resolver.impl.maven.format.MavenResolvedArtifactProcessor | ||
org.jboss.shrinkwrap.resolver.impl.maven.format.MavenCoordinateProcessor | ||
org.jboss.shrinkwrap.resolver.impl.maven.format.MavenCoordinateProcessor |
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
55 changes: 55 additions & 0 deletions
55
spi/src/main/java/org/jboss/shrinkwrap/resolver/spi/format/PathFormatProcessor.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,55 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2017, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.shrinkwrap.resolver.spi.format; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
|
||
import org.jboss.shrinkwrap.resolver.api.ResolvedArtifact; | ||
|
||
/** | ||
* {@link FormatProcessor} implementation to return a {@link Path} from the provided {@link ResolvedArtifact} argument. | ||
* | ||
* Implementation note: This format processor does not use type parameters to be able to process any type inherited from | ||
* {@link ResolvedArtifact}. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public enum PathFormatProcessor implements FormatProcessor { | ||
|
||
INSTANCE; | ||
|
||
@Override | ||
public boolean handles(Class resolvedTypeClass) { | ||
return FileFormatProcessor.INSTANCE.handles(resolvedTypeClass); | ||
} | ||
|
||
@Override | ||
public boolean returns(Class returnTypeClass) { | ||
return Path.class.equals(returnTypeClass); | ||
} | ||
|
||
@Override | ||
public Path process(ResolvedArtifact input, Class returnType) throws IllegalArgumentException { | ||
if (returnType != Path.class) { | ||
throw new IllegalArgumentException("Path processor must be called to return Path, not " + returnType); | ||
} | ||
|
||
return FileFormatProcessor.INSTANCE.process( input, File.class ).toPath(); | ||
} | ||
} |
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