Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented ArchiveMavenAssembler as a new API of MavenImporter #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually shouldn't be putting copyright notices on source files anymore. :) Recommend updating IDE templates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-pasted from MavenImporter class. I didn't know about it - is there some document/email/article about it?

* 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.api.maven.archive.assembler;

import java.io.File;

import org.jboss.shrinkwrap.api.Assignable;
import org.jboss.shrinkwrap.resolver.api.ConfigurableResolverSystem;
import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException;

/**
* ArchiveMavenAssembler is an abstraction of Maven Package phase for ShrinkWrap. It allows to package an archive based on pom.xml file.
*
* @author <a href="mailto:[email protected]">Matous Jobanek</a>
* @author <a href="[email protected]">Karel Piwko</a>
*
*/
public interface ArchiveMavenAssembler extends PomlessArchiveMavenAssembler, Assignable {

/**
* <i>Optional operation</i>. Configures this {@link ArchiveMavenAssembler} from the specified settings.xml file
*
* @param file A settings.xml {@link File} this {@link ArchiveMavenAssembler} should be configured from.
* @return This configured {@link ArchiveMavenAssembler}
* @throws IllegalArgumentException If the file is not specified, is a directory, or does not exist
* @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format
* @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by
* {@link File}
*/
ConfiguredArchiveMavenAssembler configuredFrom(File file) throws IllegalArgumentException, UnsupportedOperationException,
InvalidConfigurationFileException;

/**
* <i>Optional operation</i>. Configures this {@link ArchiveMavenAssembler} from the specified settings.xml file at the specified
* path
*
* @param pathToFile A path to a settings.xml file this {@link ArchiveMavenAssembler} should be configured from.
* @return This configured {@link ArchiveMavenAssembler}
* @throws IllegalArgumentException If the file is not specified, is a directory, or does not exist
* @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format
* @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by
* {@link File}
* @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format
*/
ConfiguredArchiveMavenAssembler configuredFrom(String pathToFile) throws IllegalArgumentException,
UnsupportedOperationException, InvalidConfigurationFileException;

/**
* <i>Optional operation</i>. Configures this {@link ArchiveMavenAssembler} from the result of
* {@link ClassLoader#getResource(String)} call using the current {@link Thread#getContextClassLoader()}
*
* @param path A {@link ClassLoader} path to a settings.xml file this {@link ArchiveMavenAssembler} should be configured from.
* @return This configured {@link ArchiveMavenAssembler}
* @throws IllegalArgumentException If the either argument is not specified or if the path can not be found
* @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by
* {@link ClassLoader} resource
* @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format
*/
ConfiguredArchiveMavenAssembler configuredFromClassloaderResource(String path) throws IllegalArgumentException,
UnsupportedOperationException, InvalidConfigurationFileException;

/**
* <i>Optional operation</i>. Configures this {@link ConfigurableResolverSystem} from the result of
* {@link ClassLoader#getResource(String)} using the specified {@link ClassLoader}
*
* @param path A {@link ClassLoader} path to a settings.xml file this {@link ArchiveMavenAssembler} should be configured from.
* @param cl A {@link ClassLoader}
* @return This configured {@link ArchiveMavenAssembler}
* @throws IllegalArgumentException If the either argument is not specified or if the path can not be found
* @throws UnsupportedOperationException If this {@link ConfigurableResolverSystem} does not support configuration by
* {@link ClassLoader} resource
* @throws InvalidConfigurationFileException If the configuration file contents are not in appropriate format
*/
ConfiguredArchiveMavenAssembler configuredFromClassloaderResource(String path, ClassLoader cl) throws IllegalArgumentException,
UnsupportedOperationException, InvalidConfigurationFileException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat Middleware LLC, 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.api.maven.archive.assembler;

/**
* Exception which in raised if assembling a Maven project is not successful.
*
* @author <a href="mailto:[email protected]">Matous Jobanek</a>
* @author <a href="mailto:[email protected]">Karel Piwko</a>
*
*/
public class ArchiveMavenAssemblerException extends RuntimeException {

/**
*
*/
private static final long serialVersionUID = 1L;

public ArchiveMavenAssemblerException(String msg) {
super(msg);
}

public ArchiveMavenAssemblerException(String msg, Throwable cause) {
super(msg, cause);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* Copyright 2013, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
Expand All @@ -14,19 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test;
package org.jboss.shrinkwrap.resolver.api.maven.archive.assembler;

/**
* Dummy class
* Instance of {@link ArchiveMavenAssembler} that has configuration from a settings.xml file loaded
*
* @author <a href="[email protected]>Karel Piwko</a>
* @author <a href="mailto:[email protected]">Matous Jobanek</a>
* @author <a href="[email protected]">Karel Piwko</a>
*
*/
public class WarClass {
public interface ConfiguredArchiveMavenAssembler extends PomlessArchiveMavenAssembler {

public static final String GREETINGS = "Hello from MavenImporter imported class";

public String greet() {
return GREETINGS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat Middleware LLC, 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.api.maven.archive.assembler;

import org.jboss.shrinkwrap.api.Assignable;
import org.jboss.shrinkwrap.resolver.api.maven.ScopeType;
import org.jboss.shrinkwrap.resolver.api.maven.filter.MavenResolutionFilter;

/**
* Instance of {@link ArchiveMavenAssembler} that has configuration from a POM file loaded
*
* @author <a href="mailto:[email protected]">Matous Jobanek</a>
* @author <a href="[email protected]">Karel Piwko</a>
*/
public interface PomEquippedArchiveMavenAssembler extends Assignable {

/**
* Based on metadata previously loaded from a Project Object Model file, adds content made during package phase to
* the archive. The content is compiled using dependencies with following scopes:
* {@link ScopeType#COMPILE}, {@link ScopeType#IMPORT}, {@link ScopeType#PROVIDED}, {@link ScopeType#RUNTIME},
* {@link ScopeType#SYSTEM} - there isn't used the scope {@link ScopeType#TEST} as it simulates Maven package build.
* <p>
* If you want to use all scopes, then use this method: {@code withBuildOutput(ScopeType.values())}
* </p>
*
* @return This modified {@link ArchiveMavenAssembler} instance with added content based on metadata previously loaded
* from a Project Object Model file.
*/
PomEquippedArchiveMavenAssembler withBuildOutput();

/**
* Based on metadata previously loaded from a Project Object Model file, adds content (classes and resources) made
* during package phase to the archive.
* The content is compiled using dependencies with the set of scopes given by the parameter
* <p>
* If you want to use all scopes, then use: {@code withBuildOutput(ScopeType.values())}
* </p>
*
* @return This modified {@link ArchiveMavenAssembler} instance with added content based on metadata previously loaded
* from a Project Object Model file.
*/
PomEquippedArchiveMavenAssembler withBuildOutput(ScopeType... scopes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is at least one ScopeType required? Maybe note the requirements for this in docs. And if one is required, you can change signature to withBuildOutput(ScopeType scope, ScopeType... scopes) to compiler-force the user to put at least one in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I didn't know how to solve this.
I don't want to have only: withBuildOutput(ScopeType... scopes) as (from my point of view) it subconsciously leads users to name all scopes when they want to use all of them (even though the behavior is described in javadoc).
However I agree that this pair of completely same methods looks quite weird. I was thinking about using method withWholeBuildOutput(), but I wanted to keep the methods names as similar as possible.
Anyway, your proposal withBuildOutput(ScopeType scope, ScopeType... scopes) makes completely sense to me.
WDYT @bartoszmajsak


/**
* Based on metadata previously loaded from a Project Object Model file, adds test content (test classes and test resources)
* made during package phase to the archive.
* The content is compiled using dependencies with all scopes:
* {@link ScopeType#COMPILE}, {@link ScopeType#IMPORT}, {@link ScopeType#PROVIDED}, {@link ScopeType#RUNTIME},
* {@link ScopeType#SYSTEM}, {@link ScopeType#TEST}
* <p>
* If you want to limit the set of used scopes, then use this method: {@link #withTestBuildOutput(ScopeType...)}
* </p>
*
* @return This modified {@link ArchiveMavenAssembler} instance with added test content based on metadata previously loaded
* from a Project Object Model file.
*/
PomEquippedArchiveMavenAssembler withTestBuildOutput();

/**
* Based on metadata previously loaded from a Project Object Model file, adds test content (test classes and test resources)
* made during package phase to the archive.
* The content is compiled using dependencies with the set of scopes given by the parameter
* <p>
* If you want to use all scopes, then use: {@code withTestBuildOutput()}
* </p>
*
* @return This modified {@link ArchiveMavenAssembler} instance with added test content based on metadata previously loaded
* from a Project Object Model file.
*/
PomEquippedArchiveMavenAssembler withTestBuildOutput(ScopeType... scopes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above in withBuildOutput


/**
* Ads dependencies defined in previously loaded Project Object Model file.
* The set of dependencies can be limited by {@link MavenResolutionFilter} and set of {@link ScopeType}s.
* <p>
* If you want to use all possible scopes, then use this method: {@link #withDependencies(MavenResolutionFilter)}
* </p>
* <p>
* If you don't want to specify {@link MavenResolutionFilter} and limit it only by set of {@link ScopeType}s,
* then use this method: {@link #withDependencies(ScopeType...)}
* </p>
* <p>
* If you don't want to limit anything and use all defined dependencies, then use this method: {@link #withDependencies()}
* </p>
*
* @return This modified {@link ArchiveMavenAssembler} instance with added dependencies limited by {@link MavenResolutionFilter} and set of {@link ScopeType}s
* @param filter A {@link MavenResolutionFilter} the added dependencies should be limited by
* @param scopes A set of {@link ScopeType}s the added dependencies should be limited by
*/
PomEquippedArchiveMavenAssembler withDependencies(MavenResolutionFilter filter, ScopeType... scopes);

/**
* Ads dependencies defined in previously loaded Project Object Model file. All scopes will be used.
* The set of dependencies can be limited by {@link MavenResolutionFilter}.
* <p>
* If you want to limit the set of dependencies also by scopes, then use this method: {@link #withDependencies(MavenResolutionFilter, ScopeType...)}
* </p>
* <p>
* If you don't want to specify {@link MavenResolutionFilter} and limit it only by set of scopes,
* then use this method: {@link #withDependencies(ScopeType...)}
* </p>
* <p>
* If you don't want to limit anything and use all defined dependencies, then use this method: {@link #withDependencies()}
* </p>
*
* @return This modified {@link ArchiveMavenAssembler} instance with added dependencies limited by {@link MavenResolutionFilter}
* @param filter A {@link MavenResolutionFilter} the added dependencies should be limited by
*/
PomEquippedArchiveMavenAssembler withDependencies(MavenResolutionFilter filter);

/**
* Ads dependencies defined in previously loaded Project Object Model file.
* The set of dependencies can be limited by set of {@link ScopeType}s.
* <p>
* If you want to limit the set of dependencies also by scopes, then use this method: {@link #withDependencies(MavenResolutionFilter, ScopeType...)}
* </p>
* <p>
* If you don't want to specify {@link MavenResolutionFilter} and limit it only by set of scopes,
* then use this method: {@link #withDependencies(ScopeType...)}
* </p>
* <p>
* If you don't want to limit anything and use all defined dependencies, then use this method: {@link #withDependencies()}
* </p>
*
* @return This modified {@link ArchiveMavenAssembler} instance with added dependencies limited by a set of {@link ScopeType}s
* @param scopes A set of {@link ScopeType}s the added dependencies should be limited by
*/
PomEquippedArchiveMavenAssembler withDependencies(ScopeType... scopes);

/**
* Ads all dependencies defined in previously loaded Project Object Model file.
* The set of dependencies can be limited by {@link MavenResolutionFilter} and set of {@link ScopeType}s.
* <p>
* If you want to limit the set of added dependencies, use any of these methods: <br>
* {@link #withDependencies(ScopeType...)}<br>
* {@link #withDependencies(MavenResolutionFilter, ScopeType...)}<br>
* {@link #withDependencies(MavenResolutionFilter)}
* </p>
*
* @return This modified {@link ArchiveMavenAssembler} instance with added dependencies

*/
PomEquippedArchiveMavenAssembler withDependencies();

<TYPE extends Assignable> TYPE as(Class<TYPE> var1, String name);

}
Loading