Skip to content
Merged
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
Expand Up @@ -15,6 +15,8 @@
*/
package io.github.ascopes.jct.containers;

import io.github.ascopes.jct.workspaces.PathRoot;
import java.util.List;
import javax.tools.JavaFileManager.Location;
import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
Expand All @@ -29,17 +31,58 @@
* {@link #getOrCreateModule(String) create} the module, and then operate on that sub-container
* group. Operations on non-module packages should operate on this container group directly.
*
* <p>Note that each container group will usually only support one package container group
* in the outputs. This is due to the JSR-199 API not providing a method for specifying which
* output location to write files to for legacy-style packages.
*
* @author Ashley Scopes
* @since 0.0.1
*/
@API(since = "0.0.1", status = Status.STABLE)
public interface OutputContainerGroup extends PackageContainerGroup, ModuleContainerGroup {

/**
* {@inheritDoc}
*
* <p>Note that this implementation will only ever allow a single container in the package
* container groups. If a container is already present, then an exception will be thrown.
*
* @param path the path to add.
* @throws IllegalStateException if a package already exists in this location.
*/
@Override
void addPackage(PathRoot path);


/**
* {@inheritDoc}
*
* <p>Note that this implementation will only ever allow a single container in the package
* container groups. If a container is already present, then an exception will be thrown.
*
* @param container the container to add.
* @throws IllegalStateException if a package already exists in this location.
*/
@Override
void addPackage(Container container);

/**
* Get the output-oriented location.
*
* @return the output-oriented location.
*/
@Override
Location getLocation();

/**
* {@inheritDoc}
*
* <p>Note that this implementation will only ever return one container in the list due to
* JSR-199 limitations.
*
* @return the list containing the package container, if it exists. Otherwise, an empty list is
* returned instead.
*/
@Override
List<Container> getPackages();
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ public OutputContainerGroupImpl(Location location, String release) {
}
}

@Override
public void addPackage(PathRoot path) {
if (super.isEmpty()) {
super.addPackage(path);
} else {
throw packageAlreadySpecified(path);
}
}

@Override
public void addPackage(Container container) {
if (super.isEmpty()) {
super.addPackage(container);
} else {
throw packageAlreadySpecified(container.getPathRoot());
}
}

@Override
public void addModule(String module, Container container) {
getOrCreateModule(module).addPackage(container);
Expand Down Expand Up @@ -173,4 +191,13 @@ private PackageContainerGroup newPackageGroup(ModuleLocation moduleLocation) {
group.addPackage(pathWrapper);
return group;
}

@SuppressWarnings("resource")
private IllegalStateException packageAlreadySpecified(PathRoot newPathRoot) {
var existingPathRoot = getPackages().iterator().next().getPathRoot();
return new IllegalStateException(
"Cannot add a new package (" + newPathRoot + ") to this output container group because " +
"a package has already been specified (" + existingPathRoot + ")"
);
}
}