|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.activemq.artemis.cli.commands.tools.config; |
| 19 | + |
| 20 | +import java.io.BufferedOutputStream; |
| 21 | +import java.io.File; |
| 22 | +import java.io.FileOutputStream; |
| 23 | +import java.io.OutputStream; |
| 24 | +import java.io.PrintStream; |
| 25 | + |
| 26 | +import org.apache.activemq.artemis.cli.commands.ActionContext; |
| 27 | +import org.apache.activemq.artemis.cli.commands.Configurable; |
| 28 | +import org.apache.activemq.artemis.core.config.impl.FileConfiguration; |
| 29 | +import picocli.CommandLine; |
| 30 | + |
| 31 | +@CommandLine.Command(name = "properties", description = "Export the broker's configuration as a properties file to be used with broker properties.") |
| 32 | +public class ExportProperties extends Configurable { |
| 33 | + |
| 34 | + @CommandLine.Option(names = "--output", description = "Output name for the file.", defaultValue = "broker.properties") |
| 35 | + private File output; |
| 36 | + |
| 37 | + @Override |
| 38 | + public Object execute(ActionContext context) throws Exception { |
| 39 | + super.execute(context); |
| 40 | + |
| 41 | + PrintStream out = context.out; |
| 42 | + OutputStream outputStream = null; |
| 43 | + |
| 44 | + System.out.println("Exporting configuration as broker.properties"); |
| 45 | + |
| 46 | + if (output == null) { |
| 47 | + throw new RuntimeException("output is a required property"); |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + if (output != null) { |
| 52 | + outputStream = new BufferedOutputStream(new FileOutputStream(output)); |
| 53 | + PrintStream printStream = new PrintStream(outputStream); |
| 54 | + context.out = printStream; |
| 55 | + } |
| 56 | + |
| 57 | + FileConfiguration configuration = readConfiguration(); |
| 58 | + configuration.exportAsProperties(output); |
| 59 | + |
| 60 | + return null; |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments