Path: blob/master/sourcetools/com.ibm.jpp.preprocessor/com/ibm/jpp/om/MacroExtension.java
6004 views
/*******************************************************************************1* Copyright (c) 1999, 2017 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package com.ibm.jpp.om;2223import java.io.File;24import java.io.FileNotFoundException;25import java.io.IOException;26import java.util.HashMap;27import java.util.Map;28import java.util.Properties;29import java.util.StringTokenizer;3031/**32* Macro Extension33*/34public class MacroExtension extends BuilderExtension {3536/**37* The macros to use for this build.38*/39private final Map<String, String> macros = new HashMap<>();4041/**42* Constructor for MacroExtension.43*/44public MacroExtension() {45super("macro");46}4748/**49* @see com.ibm.jpp.om.BuilderExtension#validateOptions(Properties)50*/51@Override52public void validateOptions(Properties options) {53String arg = options.getProperty("macro:define");5455if (arg != null) {56StringTokenizer tokenizer = new StringTokenizer(arg, ";");5758while (tokenizer.hasMoreTokens()) {59String token = tokenizer.nextToken();60int posEquals = token.indexOf('=');6162if (posEquals > 0 && posEquals < (token.length() - 1)) {63String identifier = token.substring(0, posEquals);64String replacement = token.substring(posEquals + 1);6566macros.put(identifier, replacement);67}68}69}70}7172/**73* @see com.ibm.jpp.om.BuilderExtension#notifyBuildBegin()74*/75@Override76public void notifyBuildBegin() {77// try loading the macros from the root of the sources78try {79loadProperties(macros, new File(builder.getSourceDir(), "macros.properties"));80} catch (FileNotFoundException e) {81// do nothing82} catch (IOException e) {83builder.getLogger().log("An exception occured while loading macros", Logger.SEVERITY_ERROR, e);84}85}8687/**88* @see com.ibm.jpp.om.BuilderExtension#notifyConfigurePreprocessor(JavaPreprocessor)89*/90@Override91public void notifyConfigurePreprocessor(JavaPreprocessor preprocessor) {92preprocessor.setMacros(this.macros);93}9495}969798