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

DynamicPackageOutputManager and its implementation #266

Merged
merged 8 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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,32 @@
/*
* Copyright 2014-2022 Real Logic Limited.
*
* 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
*
* https://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.agrona.generation;

/**
* Extended version of the OutputManager allowing to specify packages for selected outputs.
*/
public interface PackageGovernedOutputManager extends OutputManager
ratcashdev marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* Sets the package name to be used by the Writer obtained through the very next call to {@link
* #createOutput(java.lang.String) }. A subsequent call to
* {@link #createOutput(java.lang.String) } should use the default package name,
* whatever that is.
*
* @param packageName the packageName
*/
void setPackageName(String packageName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.agrona.generation;

import java.io.FilterWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
Expand All @@ -23,9 +25,10 @@
/**
* An {@link OutputManager} which can store source files as {@link StringWriter} buy source file name.
*/
public class StringWriterOutputManager implements OutputManager
public class StringWriterOutputManager implements PackageGovernedOutputManager
{
private String packageName;
private String basePackageName;
private final HashMap<String, StringWriter> sourceFileByName = new HashMap<>();

/**
Expand All @@ -36,7 +39,15 @@ public Writer createOutput(final String name)
final StringWriter stringWriter = new StringWriter();
sourceFileByName.put(packageName + "." + name, stringWriter);

return stringWriter;
return new FilterWriter(stringWriter)
{
@Override
ratcashdev marked this conversation as resolved.
Show resolved Hide resolved
public void close() throws IOException
{
super.close();
packageName = basePackageName;
}
};
}

/**
Expand All @@ -47,6 +58,10 @@ public Writer createOutput(final String name)
public void setPackageName(final String packageName)
{
this.packageName = packageName;
if (basePackageName == null)
{
basePackageName = packageName;
}
}

/**
Expand Down