com.metreeca.mark.tasks.Serve Maven / Gradle / Ivy
Show all versions of mark-maven-plugin Show documentation
/*
* Copyright © 2019-2020 Metreeca srl
*
* 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
*
* http://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 com.metreeca.mark.tasks;
import com.metreeca.mark.*;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import org.apache.maven.plugin.logging.Log;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.nio.file.*;
import java.time.Instant;
import java.util.AbstractMap;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import static com.metreeca.mark.Mark.extension;
import static com.sun.net.httpserver.HttpServer.create;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.time.ZoneOffset.UTC;
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
import static java.util.stream.Collectors.toMap;
/**
* Site serving task.
*
* Generates a processed version of the {@linkplain Opts#source() source} site folder in the
* {@linkplain Opts#target() target} site folder and serves it on a development grade server for testing purposes,
* watching the {@linkplain Opts#source() source} site folder for further changes to by synchronized.
*/
public final class Serve implements Task {
private static final int port=2020;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private static final int OK=200;
private static final int NotFound=400;
private static final int NotAllowed=405;
private static final Pattern BodyPattern=Pattern.compile("