blob: e31b9e5d5adfe2706b98839a4b7b1db8651a7d8a [file] [log] [blame]
/*
* Copyright (c) 2012 Google 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 com.google.eclipse.protobuf.ui.builder.protoc.command;
import static com.google.eclipse.protobuf.ui.builder.protoc.command.IResources.*;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import com.google.eclipse.protobuf.ui.preferences.compiler.core.CompilerPreferences;
/**
* @author alruiz@google.com (Alex Ruiz)
*/
class PythonProtocOption implements OutputDirectoryProtocOption {
private final CompilerPreferences preferences;
private final IProject project;
private boolean initialized;
private boolean enabled;
private IFolder outputDirectory;
private String outputDirectoryLocation;
PythonProtocOption(CompilerPreferences preferences, IProject project) {
this.preferences = preferences;
this.project = project;
}
@Override public void appendOptionToCommand(ProtocCommand command) throws CoreException {
ensureIsInitialized();
if (enabled) {
command.appendOption("python_out", outputDirectoryLocation);
}
}
@Override public IFolder outputDirectory() throws CoreException {
ensureIsInitialized();
return outputDirectory;
}
private void ensureIsInitialized() throws CoreException {
if (!initialized) {
initialize();
}
}
private void initialize() throws CoreException {
initialized = true;
enabled = preferences.pythonCodeGenerationEnabled().getValue();
if (enabled) {
String directoryName = preferences.pythonOutputDirectory().getValue();
outputDirectory = findOrCreateDirectory(directoryName, project);
outputDirectoryLocation = locationOf(outputDirectory);
}
}
}